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
Hello fellow earthling,
ReplyDeleteWhat you have posted for readers is not easily understood by
Thanks for sharing this information.
ReplyDeleteJava Program to Calculate Area and Perimeter of Rectangle .