public class WordSearch { 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'} }; String result = findWord (puzzle, "ruby"); System.out.println (result); } static String 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) { return "String " + word + " found in row=" + i + " col=" +j; } } } return "String " + word + " not found"; } }