Java program to enter the length and breadth of a rectangle and find its area
ADVERTISEMENTS
Java program to enter the length and breadth of a rectangle and find its area.
There are you will learn how to find the area of a rectangle in Java language.
Formula:
P = l * w
where:
P
= perimeter
l
= length of the rectangle
w
= width of the rectangle
Let us understand this through the Java program:
// Java program to find the area of a rectangle
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the length & width of the rectangle::\n");
// Reading data using readLine
float l = in.nextFloat();
float w = in.nextFloat();
float a;
/* Calculate area of rectangle */
a = l * w;
System.out.print("\n");
System.out.println("Area of rectangle = " + a + " units");
}
}
Output:
Enter the length & width of the rectangle::
5
7
Area of rectangle = 35.0 units