home
search
help
profile
liking the experience? our app is even better
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now  
showing results for java program to calculate area of circle rectangle and triangle using switch
1// Java program to calculate area of circle rectangle and triangle using switch statement
2import java.util.Scanner;
3public class FindAreaUsingSwitchStatement 
4{
5   public static void main(String[] args) 
6   {
7      Scanner sc = new Scanner(System.in);
8      System.out.println("MENU:");
9      System.out.println("1.Area of circle");
10      System.out.println("2.Area of triangle");
11      System.out.println("3.Area of rectangle");
12      System.out.println("Please enter any of the above option: ");
13      int num = sc.nextInt();
14      switch(num)
15      {
16         case 1: System.out.println("Please enter radius of circle: ");
17         double radius = sc.nextFloat();
18         double areaCircle = (22 * radius * radius) / 7;
19         System.out.println("Area of circle is: " + areaCircle);
20         break;
21         case 2: System.out.println("Please enter base and height of triangle: ");
22         double base = sc.nextFloat();
23         double height = sc.nextFloat();
24         double areaTriangle = (base* height) / 2;
25         System.out.println("Area of triangle is: " + areaTriangle);
26         break;
27         case 3: System.out.println("Please enter length and breadth of rectangle: ");
28         int length = sc.nextInt();
29         int breadth = sc.nextInt();
30         int areaRectangle = length * breadth;
31         System.out.println("Area of ractangle is: " + areaRectangle);
32         break;
33         default:System.exit(0);
34      }
35      sc.close();
36   }
37}
upvote
downvote
source