Write a program in java to accept the length and breadth of a rectangle. Calculate and display the
area, perimeter or diagonal of the rectangle as per the user's choice.
plzz help
Answers
Answer:
import java.util.*;
public class Menu
{
public static void main {String args[] }
{
Scanner in = new Scanner (System.in)
int l, b , n, a , p;
double d;
System.out.println( "Enter length and breadth of a rectangle");
a = in.nextInt();
b = in.nextInt();
System.out.println( "Enter 1 for area, 2 for perimeter, 3 for diagonal);
System.out.println("Enter your choice");
n = in.nextInt();
switch (n)
{
case 1:
a = l*b;
System.out.println("Area of rectangle =" +l);
break;
case 2:
p = 2(l+b);
System.out.println("Perimeter of rectangle =" +p);
break;
case 3;
d = Math.sqrt(l*l + b*b);
System.out.println("Diagonal of rectangle =" +d);
break;
default:
System.out.println(" wrong choice !!");
}
}
}