Write a program to find if the word is present vertically in 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 |
true |
B A T C Q |
false |
class FindWordPresentVerticallyInCharacterMatrix
{ public static void main(String s[])
{
char[][] input = {{'A', 'S', 'C', 'D'}, {'C', 'A', 'T', 'O'}, {'Q', 'M', 'T', 'S'}, {'V', 'X', 'Z', 'E'}};
System.out.println("DOSE is present vertically : " + isWordIsPresentVerticallyInMatrix(input, "DOSE"));
}
public static boolean isWordIsPresentVerticallyInMatrix(char[][] matrix, String searchWord) {
//Write code here to find if the word is present vertically in the given matrix.
}
}
Topic: getChars() Method In Java