Write Java program to Find Area of Rectangle


This is a Java program that calculates the area of a rectangle given its length and width.

  • The program first declares three double variables: len, wid, and area.
  • It then prompts the user to enter the length and width of the rectangle using the nextDouble() method of the Scanner class.
  • To calculate the area of the rectangle, the program multiplies the length and width together and stores the result in the area variable.
  • Finally, the program outputs the calculated area to the console using the println() method, preceded by a string indicating that the value being printed is the area of the rectangle.

Source Code

import java.util.*;
public class Area_Rectangle
{
	public static void main(String []args)
	{
		double len,wid,area;
		Scanner input = new Scanner(System.in);
		System.out.print("Enter the Length : ");
		len = input.nextDouble();
		System.out.print("Enter the width : ");
		wid = input.nextDouble();		
		area = len*wid; //Area = Length*width
		System.out.println("Area of Rectangle : " + area);    
	}
}

Output

Enter the Length : 14
Enter the width : 17
Area of Rectangle : 238.0