# Find Area of a Rectangle in Java

The formula for finding the area of a rectangle is,

area = length * width

## Calculate Area of a Rectangle in Java

The following program calculates area of a rectangle in Java. The program asks the user for length and width values and then outputs the result in the console. We use BufferedReader to read a line of string and then use the parseDouble method of the Double class to convert the string to a number.

This program also illustrates the decorator pattern. We first decorate the console input stream (System.in) with a InputStreamReader and then again decorate it with BufferedReader. BufferedReader enables us to read a line of data from an input stream.

```// Java program to find area of a rectangle
import java.io.IOException;

public class RectangleArea {

public static void main(String[] args) throws IOException{

System.out.print("Please enter length of the rectangle : ");

System.out.print("Please enter width of the rectangle : ");

System.out.println("Area of the rectangle : "+length*width);

}

}```

Do you have a programming problem that you are unable to solve? Please send us your problem and we will publish the solution on this site within 48 hours! Please email us.

### One Response to “Find Area of a Rectangle in Java”

1. import java.util.Scanner;
class Rectangle
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println(“plz enter length”);
int l=sc.nextInt();
System.out.println(“plz enter width”);
int w=sc.nextInt();
System.out.println(“Area of Rectangle=”+(l*w));
}
}