Java Program to Calculate Area of Rectangle

In this tutorial, we will learn how to write a Java Program to calculate the Area of Rectangle.
We will read input from the console using Scanner class.

Java Program to Calculate Area of Rectangle

package com.javaguides.java.tutorial;

import java.util.Scanner;

/**
 * Java Program to Calculate Area of Rectangle
 * 
 * @author https://www.sourcecodeexamples.net/
 *
 */
public class JavaProgram {
    public static void main(String[] args) {

        try (Scanner scanner = new Scanner(System.in)) {
            System.out.println("Enter the length of Rectangle:");
            double length = scanner.nextDouble();
            System.out.println("Enter the width of Rectangle:");
            double width = scanner.nextDouble();
            // Area = length*width;
            double area = length * width;
            System.out.println("Area of Rectangle is:" + area);
        }
    }
}
Output:
Enter the length of Rectangle:
10
Enter the width of Rectangle:
20
Area of Rectangle is:200.0

Related Java Programs


Comments