Find the vertex diagonally opposite to the vertex M from an N | Java program for the above approach ; Function to return the required vertex ; Case 1 : ; Case 2 : ; Driver Code
class GFG { static int getPosition ( int N , int M ) { if ( M > ( N / 2 ) ) { return ( M - ( N / 2 ) ) ; } return ( M + ( N / 2 ) ) ; } public static void main ( String [ ] args ) { int N = 8 , M = 5 ; System . out . print ( getPosition ( N , M ) ) ; } }