Loading...
Loading...
Loading...
A flooring shop works out areas all day. Square tiles have one side; rooms are rectangles with a length and a width.
Write two overloaded methods with the same name: static long area(long side) for a square and static long area(long length, long width) for a rectangle. For each query, call the right one and print the area.
1 s (a square with side s) or 2 l w (a rectangle with length l and width w).Example
Input
3 1 4 2 3 5 1 1
Output
16 15 1
4 × 4 = 16, 3 × 5 = 15 and 1 × 1 = 1.
Try the problem first. Open one hint at a time.
Java picks the method by the number of arguments: area(s) calls the one-parameter version.
Read the query type first, then read one or two more numbers.
Use long so 10^6 × 10^6 does not overflow.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor