Write a program to find if the word is present in the character matrix in any direction. The directions are horizontal, vertical, upward diagonal, downward diagonal and their opposite directions.
Input (char[][], String) | Output (Boolean) |
---|---|
B A T C |
true |
B A T C |
true |
Q E A |
false |
Q E A D R |
true |
Q E A D R |
true |
Q E A |
true |
Q E N |
true |
Q E A D M |
true |
Q E A D N |
true |
class FindWordPresentInCharacterMatrixBiDirectional
{ public static void main(String s[])
{
char[][] input = {{'A', 'S', 'C', 'D'}, {'C', 'T', 'A', 'F'}, {'Q', 'M', 'A', 'S'}, {'V', 'X', 'Z', 'C'}};
System.out.println("CAT is present : " + isWordIsPresentInMatrix(input, "CAT"));
}
public static boolean isWordIsPresentInMatrix(char[][] matrix, String searchWord) {
//Write code here to find if the word is present in the given matrix.
}
//Write code here if we want create any new methods.
}
Topic: getChars() Method In Java