Write a program to find if the word is present horizontally in a character matrix.
Input (char[][], String) | Output (Boolean) |
---|---|
B A T C |
true |
Q E A |
false |
Q E A D R |
false |
Q E A |
false |
B A T C Q |
true |
class FindWordPresentHorizontallyInCharacterMatrix
{ public static void main(String s[])
{
char[][] input = {{'A', 'S', 'C', 'D'}, {'C', 'A', 'T', 'F'}, {'Q', 'M', 'T', 'S'}, {'V', 'X', 'Z', 'A'}};
System.out.println("CAT is present horizontally : " + isWordIsPresentHorizontallyInMatrix(input, "CAT"));
}
public static boolean isWordIsPresentHorizontallyInMatrix(char[][] matrix, String searchWord) {
//Write code here to find if the word is present in the given matrix.
}
}
Topic: getChars() Method In Java