(Area and perimeter of a rectangle) Write a program that displays the area and perimeter of a rectangle with the width of 4.5 and height of 7.9 using the following formula:
area = width * height
Answer
/**
Program - 09
(Area and perimeter of a rectangle)
Write a program that displays the area and perimeter of a rectangle with the width of 4.5 and height of 7.9 using the following formula:
area = width * height
**/
public class HelloWorld
{
public static void main(String args[])
{
System.out.println("Area = ");
System.out.println(4.5 * 7.9);
System.out.println("Perimeter = ");
System.out.println((4.5 + 7.9) * 2);
}
}
OUTPUT
Area =
35.550000000000004
Perimeter =
24.8
In this program the background knowledge which we have to acquire to solve this program is using:
1) Formula of Area = (length * breadth)
2) Formula of Perimeter = 2(length * breadth)
Note: As System.out.println(); is used, therefore the value of Area and Perimeter gets printed in the new line.
If you have any doubts or questions, please let me know.