write a program to input length and breadth of a rectangle . calculate and display the area, perimeter or diagonal of the rectangle as per the users choice
Answers
Answer:
Import java.util.*;
public class rectangle
{
public static void main()
{
Scanner sc =new Scanner (System.in);
System.out.println("enter length,breadth of rectangle");
double l=sc.nextDouble();
double b=sc.nextDouble ();
System.out.println ("enter choice");
int ch=sc. nextInt();
switch(ch)
{
case1:
double a;
a=l*b;
System.out.println ("area="+a);
break;
}
case 2:
{
double p;
p=2*(l+b);
System. out.println ("perimeter="+p);
break;
}
case 3:
{
double d=Math.sqrt(l*l+b*b);
System. out.println ("diagonal="+d);
break;
}
default :
{
System.out.println ("wrong choice");
}
}
}
ʜᴏᴘᴇ ɪᴛ ʜᴇʟᴘs
choice = "Yes"
while choice == "Yes":
l = float(input("Enter the length of the rectangle: "))
b = float(input("Enter the breadth of the rectangle: "))
print("Would you like to find:", "1. The area", "2. The perimeter", "3. The diagonal", sep = "\n")
op = int(input("Enter the number of choice of operation: ") )
if op == 1:
area = l*b
print(area, "is the area of the rectangle.")
elif op == 2:
pm = 2*(l + b)
print(pm, "is the perimeter of the rectangle.")
elif op == 3:
dg = (l**2 + b**2)**(1/2)
print(dg, "is the diagonal of the rectangle.")
print()
choice = input("Would you like to go again? [Yes/No]: ")