Final direction after visiting every cell of Matrix starting from ( 0 , 0 ) | Java program to find the direction when stopped moving ; Function to find the direction when stopped moving ; Driver code ; Given size of NxM grid ; Function Call
class GFG { static void findDirection ( int n , int m ) { if ( n > m ) { if ( m % 2 == 0 ) System . out . print ( "UpNEW_LINE"); else System . out . print ( "DownNEW_LINE"); } else { if ( n % 2 == 0 ) System . out . print ( "LeftNEW_LINE"); else System . out . print ( "RightNEW_LINE"); } } public static void main ( String [ ] args ) { int n = 3 , m = 3 ; findDirection ( n , m ) ; } }