settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Rectangle Area - Java Task

+6 votes

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

asked in Java category by user eiorgert
edited by user golearnweb

1 Answer

+1 vote
 
Best answer

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);
    }
}

 

answered by user golearnweb
selected by user golearnweb
...