Java program to calculate the area of rectangle


How to calculate the area of a rectangle

The area of a rectangle is equal to the length multiplied by the width.
The program asks the user to input the length and width of a rectangle. 
The formula for the area is:
Area = width * height
Java code to calculate area of rectangle:
import java.util.Scanner;
public class RectangleArea {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        double length, width, area;
        System.out.println("Area of Rectangle");
        System.out.print("Enter the length of rectangle: ");                                                            
        length = input.nextDouble();
        System.out.print("Enter the width of rectangle: ");
        width = input.nextDouble();
        area = length * width;
        System.out.println("Area of rectangle: " + area);  
    }
}
Sample output:
Area of Rectangle
Enter the length of rectangle: 5,6
Enter the width of rectangle: 4,7
Area of rectangle: 26.32
 

2 comments :

  1. Hello fellow earthling,
    What you have posted for readers is not easily understood by

    ReplyDelete