Write a menu driven program to print area of rectangle, perimeter of rectangle, and diagonal of rectangle
Answers
Answer:
import java.util.*;
public class Rectangle
{
public static void main(String args[ ])
{
Scanner in=new Scanner(System.in);
int ch,l,b;
System.out.println("Enter length:");
l=in.nextInt();
System.out.println("Enter breath:");
b=in.nextInt();
System.out.println("Enter 1 to calculate the area of rectangle");
System.out.println("Enter 2 to calculate the perimeter of rectangle");
System.out.println("Enter 3 to calculate the diagonal of rectangle");
System.out.println("Enter the operation you want to perform");
ch=in.nextInt();
switch(ch)
{
case 1:
int ar=0;
ar=l*b;
System.out.println("The area of rectangle="+ar);
break;
case 2:
int pr=0;
pr=2*(l+b);
System.out.println("The perimeter of rectangle="+pr);
break;
case 3:
double d=0.0;
d=Math.sqrt(l*l+b*b);
System.out.println("The diagonal of the rectangle="+d);
break;
default:
System.out.println("Invalid choice");
}
}