Problem specification: There is a grid of NXN squares. We can easily determines how many different rectangles (squares are excluded) there are in the grid. For example, in a 3X3 grid, you can find 22 different rectangles, marked as the green rectangles. You can see that we did not count the red ones as they are squares. In this assignment, you will write a Java program that takes the value of N as input and determines the total area of all the rectangles in the grid. Assume that the smallest squares in the grid have length 1. So a 3X2 rectangle will have an area of 6. For example, the total area of all the rectangles in the 3X3 grid is 66. Input specification: The input is a single integer which represents N, the size of the square grid. The value of N is in the range 1 ≤ ≤ 70. Output specification: The output of your program is a single integer that represents the total area of all the rectangles in the grid. Note: You must not print anything extraneous (such as “Please enter N” or “the result is”). Sample input: Sample output: 8 10 22 12432 43032 3882032
Problem specification:
There is a grid of NXN squares. We can easily determines how many different rectangles (squares are excluded) there are in the grid. For example, in a 3X3 grid, you can find 22 different rectangles, marked as the green rectangles. You can see that we did not count the red ones as they are squares. In this assignment, you will write a Java
of N as input and determines the total area of all the rectangles in the grid. Assume that the smallest squares in the grid have length 1. So a 3X2 rectangle will have an area of 6. For example, the total area of all the rectangles in the 3X3 grid is 66.
Input specification:
The input is a single integer which represents N, the size of the square grid. The value of N is in the range 1 ≤ ≤ 70.
Output specification:
The output of your program is a single integer that represents the total area of all the rectangles in the grid. Note: You must not print anything extraneous (such as “Please enter N” or “the result is”).
Sample input: |
Sample output: |
8 10 22 |
12432 43032 3882032 |
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images