Area of Rectangle

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

JavaBeginner
Java
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

We apply the formula area = length × breadth.