import java.util.Scanner;
class AreaOfRectangle {
public static void main (String[] args)
{
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);
}
}
Enter the length of Rectangle:
2
Enter the width of Rectangle:
8
Area of Rectangle is:16.0
public class RectangleArea {
public static void main(String[] args) {
double length = 10;
double width = 5;
double area = length * width;
System.out.println("Area of rectangle is " + area);
}
}
Area of rectangle is 50.0
length
and width
and initialize them with the values 10 and 5 respectively. We then calculate the area
of the rectangle by multiplying the length and width, and store the result in a double
variable area. Finally, we print the area of the rectangle using a formatted string.