class Coord { int i, j; } public class WordSearch6 { public static void main (String[] argv) { char[][] puzzle = { {'n', 'o', 'h', 't', 'y', 'p', 's'}, {'m', 'i', 'a', 'r', 'y', 'c', 'c'}, {'l', 'l', 'e', 'k', 's', 'a', 'h'}, {'r', 'u', 'b', 'y', 'v', 'm', 'e'}, {'e', 'h', 'h', 'a', 'l', 'l', 'm'}, {'p', 'c', 'j', 'n', 'i', 'c', 'e'}, {'r', 'e', 'e', 'k', 'b', 'i', 'p'} }; Coord c = findWord (puzzle, "ruby"); if (c == null) { System.out.println ("Not found"); } else { System.out.println ("Found in row " + c.i + " column " + c.j); } } static Coord findWord (char[][] puzzle, String word) { // First convert the String into a char array. char[] letters = word.toCharArray (); // Now try every possible starting point in the puzzle array. for (int i=0; i= puzzle[i].length) || (letters[k] != puzzle[i][j+k]) ) { // Not a match. found = false; break; } } // If we went the whole length of the word, we found it. if (found) { Coord c = new Coord (); c.i = i; c.j = j; return c; } } } return null; } }