Q:

Write a Java program to print the area and perimeter of a rectangle

0

 Write a Java program to print the area and perimeter of a rectangle
Test Data:
Width = 5.5 Height = 8.5

Expected Output
Area is 5.6 * 8.5 = 47.60
Perimeter is 2 * (5.6 + 8.5) = 28.20

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public class Exercise13 {
 
   public static void main(String[] strings) {

        final double width = 5.6;
        final double height = 8.5;

        double perimeter = 2*(height + width);
		
        double area = width * height;			
		
		System.out.printf("Perimeter is 2*(%.1f + %.1f) = %.2f \n", height, width, perimeter);

        System.out.printf("Area is %.1f * %.1f = %.2f \n", width, height, area);
    }
}

Sample Output:

Perimeter is 2*(8.5 + 5.6) = 28.20 
Area is 5.6 * 8.5 = 47.60

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now