Java Program to Find Number of Rectangles in N*M Grid
public class Main
{
// Driver method
public static void main(String[] args)
{
//Value of 'n' and 'm' are declared
int n = 2, m = 2;
//calling the rectangleCount() user defined method
System.out.println("Number of rectangle : "+rectangleCount(n, m));
}
//rectangleCount() method to find the number of rectangles
public static long rectangleCount(int n, int m)
{
return (m * n * (n + 1) * (m + 1)) / 4;
}
}
Output:
Number of rectangle : 9
