Computer Science, asked by snehal1525, 9 months ago

write a program in using switch case to print the area of geometrical shapes circle, square,traingle.

(in Java)​

Answers

Answered by architameriya
2

Answer:

The programs are follwing

Explanation:

Area of circle:-

public class Area.

int r;

double p = 3.14, area;  

Scanner s = new Scanner(System.

System. out. print("Enter radius of circle:");

r = s. nextInt();

area = pi * r * r;

System. out. println("Area of circle:"+area);

Area of rectangle:-

public class rectangle{

public static void main(String args[])

{

int width=5;

int height=10;

int area=width*height;

System.out.println("Area of rectangle="+area);

}

Area of Square

public class shpere{

public static void main(String args[])

{

int s=13;

int area_square=s*s;

System.out.println("Area of the square="+area_square);

}

Area of Triangle:-

import java.util.Scanner;

public class AreaOfTriangle {

  public static void main(String args[]){

     int height, base, area;

     Scanner sc = new Scanner(System.in);

     System.out.println("Enter the height of the triangle ::");

     height = sc.nextInt();

     System.out.println("Enter the base of the triangle ::");

     base = sc.nextInt();

     area = (height* base);

     System.out.println("Area of the triangle is ::"+area);

  }

}

Answered by imtiyazallam
1

Answer:

import java.util.*;

public class Test {

   public static void main(String args[]) {

       Scanner sc = new Scanner(System.in);

       char menu;

       double a, b;

       System.out.println("Find area of:");

       System.out.println("1) Circle");

       System.out.println("2) Square");

       System.out.println("3) Triangle");

       System.out.print("Enter code / serial number:");

       menu = (sc.next()).charAt(0);

       switch (menu) {

           case 1:

               System.out.print("Enter Radius:");

               a = sc.nextDouble();

               System.out.println("Area of circle is: " + (Math.PI * Math.pow(a, 2)));

               break;

           case 2:

               System.out.print("Enter side:");

               a = sc.nextDouble();

               System.out.println("Area of Square is: " + (Math.pow(a, 2)));

               break;

           case 3:

               System.out.print("Enter Base:");

               a = sc.nextDouble();

               System.out.print("Enter Height:");

               b = sc.nextDouble();

               System.out.println("Area of triangle is: " + (1.0 / 2 * a * b));

               break;

       }

   }

}

Similar questions