# Java program to calculate area of rectangle

Let’s learn java program to calculate area of rectangle.

## Java program to calculate area of rectangle

Java program to find area of rectangle is the most common java program interview question.

In java program to find area of rectangle user will be prompted to enter the length and width of a rectangle.

Length and width of a rectangle are stored in variable “length” and variable “width”. Then using above input values we calculate area of rectangle.

Also read – system arraycopy() method in java

// calculate rectangle 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 : 5
Please enter width of rectangle : 2
Area : 10.0

Similarly let’s see java program to find area of rectangle using functions,

```import java.util.Scanner;
public class RectangleArea
{
public static void areaRectangle(double width, double height)
{
double area;
area = width * height;
System.out.println("Area of rectangle : " + area);
}

public static void main(String[] args)
{
double width, height;
Scanner sc = new Scanner(System.in);
System.out.println("Please enter length of rectangle : ");
width = sc.nextDouble();
System.out.println("Please enter width of rectangle : ");
height = sc.nextDouble();
areaRectangle(width, height);
sc.close();
}
}

```

Output:

Please enter length of rectangle : 8
Please enter width of rectangle : 6
Area of rectangle = 48.0

Similarly let’s see java program to find the area of rectangle using class and object – click here.