Sum of the count of number of adjacent squares in an M X N grid | Java implementation of the above approach ; function to calculate the sum of all cells adjacent value ; Driver Code
class GFG { static int sum ( int m , int n ) { return 8 * m * n - 6 * m - 6 * n + 4 ; } public static void main ( String [ ] args ) { int m = 3 , n = 2 ; System . out . println ( sum ( m , n ) ) ; } }