Problem:2.12


 Question 2.12: 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


Solution: 

package com.company;
import java.util.Scanner;
public class Lab2problem12 {
    public static void main(String[] args)
    {
        Scanner Obj =new Scanner(System.in);
        System.out.println("enter the width:");
        double a =Obj.nextDouble();
        System.out.println("enter the Hight:");
        double b =Obj.nextDouble();

        double area =(double) a * b;

        double  perimeter =(double) 2*(a+b);
        System.out.println("the area: " + area);
        System.out.println("the perimeter: " + perimeter);
    }
}

Previous Post Next Post