Java Programming | Area of Rectangle


This is a tutorial for area of rectangle in java. The program calculates the area and prints it. The program is extendable. Go enjoy the program. Lets begin……

Program for area of rectangle in java.

//import Scanner as we require it.
import java.util.Scanner;

// the name of our class its public
public class RectArea {
//void main
public static void main (String[] args)
//declare int
int area,a,b;
//print message
System.out.println("Enter length and breadth of Rectangle:");
//Take input
Scanner input = new Scanner(;
a = input.nextInt();
b = input.nextInt();
area = a*b;
//print the area
System.out.println("Area = "+area);


Enter length and breadth of Rectangle:
Area = 32

How it works

  1. The program prints the message to enter numbers.
  2. The user enters two sides of rectangle.
  3. Area is calculated.
  4. The area is printed.

Extending it

The program can be extended by taking more different shapes and calculating their area.


  1. Import the Scanner.
  2. Declare the class as public
  3. Add the void main function
  4. Add system.out.println() function with the message to enter two sides of rectangle.
  5. Declare input as Scanner.
  6. Take the breadth and length and save it in variable.
  7. Calculate area and save it in other variable.
  8. Add system.out.println() function to print the area.

At the end.

You learnt creating the Java program for Area of Rectangle. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Sharing options: