3
28/10/2024 7:14 pm
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:
1 Answer
2
28/10/2024 7:15 pm
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); } }