Find Area of Rectangle in Java
Here you will learn that, How to find Area of Rectangle in Java programming.
A rectangle is a four-sided shape with right angles. Its opposite sides have equal length, and diagonals bisect at right angles.
Formula:
Area = Length * Width
Example:
Length = 10
Width = 8
Area of Rectangle is 80
Find Area of Rectangle in Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | //Area of Rectangle in Java import java.util.Scanner; public class RectangleArea { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the length : "); double length = scanner.nextDouble(); System.out.print("Enter the width : "); double width = scanner.nextDouble(); scanner.close(); // calculate area of rectangle double area = length * width; System.out.println("The area of the rectangle is: " + area); } } |
Output
C:\CodeRevise\java>javac RectangleArea.java
C:\CodeRevise\java>java RectangleArea
Enter the length : 10
Enter the width : 7
The area of the rectangle is: 70.0
Check out our other Java Programming Examples