Write a program to accept length and breadth of a rectangle. Calcul
and display the area, perimeter or diagonal of the rectangle as pe
the user's choice.
Answers
Answered by
2
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");
}
}
}
Explanation:
Similar questions
India Languages,
1 month ago
Math,
1 month ago
Accountancy,
3 months ago
Science,
3 months ago
English,
10 months ago
Math,
10 months ago