
/*
Online Java - IDE, Code Editor, Compiler

Online Java is a quick and easy tool that helps you to build, compile, test your programs online.
*/

public class Main
{
    public static void main(String[] args) {
        System.out.println("Welcome to Online IDE!! Happy Coding :)");
        
        String word = "FOAM";
        char [] wordChars = word.toCharArray();
        
        
        char [][] matrix = {{'F','O','A','M'}, 
                            {'O','B','Q','P'}, 
                            {'A','N','O','B'}, 
                            {'M','A','S','S'}   };
        
        int count=0;
        
        /// convert word into charracter Array
        
        System.out.println("******Checking each row*********");
        //check each row for match in word
        
        for (int i=0; i<matrix[0].length; i++)
        
        {
            count=0;
            System.out.println("\nvalue i:" + i);
            
            
            System.out.println(count);
            
        
        for (int j=0; j<matrix.length; j++)
        {
            System.out.println("value j:" + j);
            
            
            System.out.println("Processing character from word: " + word.charAt(j));
            System.out.println("Processing character from matrix: " + matrix[i][j]);
            
            
            if (matrix[i][j]==word.charAt(j))
            {
                //System.out.println("Match in character: " + matrix[i][j]);
                
                count++;
                
                System.out.println("count is: " + count);
                System.out.println("length of word is: " + word.length());
                
                if (count==word.length())
                {
                    System.out.println("\nMatch found in word: " + word + " on row: " + i);
                }
            }
            
           
        }
        }
        
         //check each column for match in word
         
        System.out.println("\n***********Checking each column************");
        
        for (int i=0; i<matrix.length; i++)
        
        {
            count=0;
            System.out.println("\nvalue i:" + i);
            
            
            
        for (int j=0; j<matrix[0].length; j++)
        {
            System.out.println("value j:" + j);
            
            
            System.out.println("Processing character from word: " + word.charAt(j));
            System.out.println("Processing character from matrix: " + matrix[j][i]);
            
            
            if (matrix[j][i]==word.charAt(count))
            {
                count++;
                
                System.out.println("count is: " + count);
                System.out.println("length of word is: " + word.length());
                
                if (count==word.length())
                {
                    System.out.println("\nMatch found in word: " + word + " on column: " + i +"\n");
                }
            }
            
           
        }
        }
        
        
        
        
        
        
        
        
        
        
        
        
        
    }
}
