Area of Rectangle

Calculate the area of a rectangle given its length and breadth.

BeginnerTopic: Module 1: Basic Java Programs
Back

Java Area of Rectangle Program

This program helps you to learn the fundamental structure and syntax of Java programming.

Try This Code
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter length: ");
        double length = sc.nextDouble();
        System.out.print("Enter breadth: ");
        double breadth = sc.nextDouble();

        double area = length * breadth;
        System.out.println("Area of rectangle = " + area);

        sc.close();
    }
}
Output
Enter length: 4
Enter breadth: 3
Area of rectangle = 12.0

Understanding Area of Rectangle

We apply the formula area = length × breadth.

Note: To write and run Java programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Java Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Java programs.

Table of Contents