Home

//write a menu driven program to
//find the area of the following
// i) TRIANGLE
//ii) RECTANGLE
//iii)CIRCLE
//iv)RHOMBUS

–> import java.util.*;
public class Main
{
public static void main(String[] args)
{
int c;
double h,ba,ar,l,b,r,d1,d2;
Scanner sc=new Scanner(System.in);
System.out.println(“press 1 for finding area of triangle”);
System.out.println(“press 2 for finding area of rectangle”);
System.out.println(“press 3 for finding area of circle”);
System.out.println(“press 4 for finding area of rhombus”);
c=sc.nextInt();
switch (c)
{
case 1:
System.out.println(“enter the base”);
ba=sc.nextDouble();
System.out.println(“enter the height”);
h=sc.nextDouble();
ar=0.5*ba*h;
System.out.println(“Area of the triangle=”+ar);
break;
case 2:
System.out.println(“enter the length”);
l=sc.nextDouble();
System.out.println(“enter the wide”);
b=sc.nextDouble();
ar=l*b;
System.out.println(“The area of rectangle is “+ar);
break;
case 3:
System.out.println(“enter the radius”);
r=sc.nextDouble();
ar=22/7.0 *r*r;
System.out.println(“The area of circle is “+ar);
break;
case 4:
System.out.println(“enter diagonal 1”);
d1=sc.nextDouble();
System.out.println(“enter diagonal d2”);
d2=sc.nextDouble();
ar=0.5*d1*d2;
System.out.println(“the area of rhombus=”+ar);
break;
default:
System.out.println(“Wrong choice”);
}
}
}

  1. To download the above program press the download button
  2. Page created by Shusnato
Design a site like this with WordPress.com
Get started