[Solved] Rectangle Area - Java Task

  

3
Topic starter

Write a program that enters the sides of a rectangle (two integers a and b) and calculates and prints the rectangle's area.

Examples:

calculate rectangle area in java

1 Answer
2

You must use the Scanner class in Java: The Scanner class is a class in java.util, which allows the user to read values of various types.

Here is the solution:

import java.util.Scanner;
 
public class Pr_01_RectangleArea {
    public static void main(String[] args) {
 
        Scanner scanner = new Scanner(System.in);
 
        System.out.println("Please write the first side of the rectangle:");
        int sideOne = scanner.nextInt();
 
        System.out.println("Please write the second side of the rectangle:");
        int sideTwo = scanner.nextInt();
 
        System.out.println("The area of your rectangle is:" );
        System.out.println(sideOne * sideTwo);
    }
}
Share: