Today we are going to learn java program to calculate area of rectangle.

#### Java program to calculate area of rectangle

In rectangle java program user will be prompted to enter the length and width of a rectangle. Then using input values we calculate the area.

Also read – calculate perimeter of rectangle in java

// Area = length * width

import java.util.Scanner; public class RectangleArea { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Please enter length of rectangle : "); double length = sc.nextDouble(); System.out.println("Please enter width of rectangle : "); double width = sc.nextDouble(); double area = length * width; System.out.println("Area : " + area); sc.close(); } }

**Output:**

Please enter length of rectangle : 2

Please enter width of rectangle : 5

Area : 10.0

Similarly we can calculate area of rectangle without using scanner class.

import java.util.*; public class AreaRectangle { public static void main(String []args) { double length = 30.0;

double width = 40.0; double area = length * width; System.out.println("Area : " + area); }

}

**Output:**

Area : 1200.0