Here, you will learn how to calculate the Area of a Rectangle using the Formula (Length * Breadth). The program takes the user input for length and breadth, calculates the result, and displays the result on the screen.
If you do not know about the operators in java, click the link below to learn about operators as this program is using one.
Java Program to Calculate the Area of a Rectangle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import java.util.Scanner; public class AreaRectangle { public static void main(String[] args) { int len, br, result; Scanner sc = new Scanner(System.in); //Taking Inputs from Users System.out.print("Enter the length: "); len = sc.nextInt(); System.out.print("Enter the breadth: "); br = sc.nextInt(); sc.close(); result = len * br; System.out.println("Area of a rectangle: " + result); } } |
Output:
Enter the length: 2
Enter the breadth: 5
Area of a rectangle: 10