Computer Science, asked by mkhetan122, 1 year ago

9. Write a menu driven java program to calculate:
(a) Area of a circle = p*r), where p = 22
(6) Area of a square = side*side
(c) Area of a rectangle = length breadth
Enter 'c' to calculate area of circle, 's' to calculate area of square and 'r' to calculate
area of rectangle.​

Answers

Answered by sswaraj04
160

Answer:

import java.util.Scanner;

public class Geometry

{

    public static void main(String args[])

     {

       Scanner s=new Scanner(System.in);

       System.out.println("MENU:");

       System.out.println("Enter c for Area of a Circle");

       System.out.println("Enter s for Area of a Square");

       System.out.println("Enter r for Area of a Rectangle");

       char op=s.next(). c h a r A t (0);

       switch(op)

       {

         case 'c': System.out.println("Enter radius:");

                   float r=s.nextFloat();

                   float ac=3.14f*r*r;

                   System.out.println("Area:"+ac);

                   break;

         case 's': System.out.println("Enter side:");

                   int x=s.nextInt();

                   int as=x*x;

                   System.out.println("Area:"+as);

                   break;

         case 'r': System.out.println("Enter height and base:");

                   float h=s.nextFloat();

                   float bs=s.nextFloat();

                   float art=0.5f*h*bs;

                   System.out.println("Area:"+art);

                   break;

         default: System.out.println("Wrong choice");

        }

   }

}

Explanation:

No spaces at c h a r A t just brainly doesn't allow it ..idk why

Hope it helps :-)

Answered by shirisha1981
37

Answer:import java.util.Scanner;

public class Geometry

{

   public static void main(String args[])

    {

      Scanner s=new Scanner(System.in);

      System.out.println("MENU:");

      System.out.println("Enter c for Area of a Circle");

      System.out.println("Enter s for Area of a Square");

      System.out.println("Enter r for Area of a Rectangle");

      char op=s.next(). c h a r A t (0);

      switch(op)

      {

        case 'c': System.out.println("Enter radius:");

                  float r=s.nextFloat();

                  float ac=3.14f*r*r;

                  System.out.println("Area:"+ac);

                  break;

        case 's': System.out.println("Enter side:");

                  int x=s.nextInt();

                  int as=x*x;

                  System.out.println("Area:"+as);

                  break;

        case 'r': System.out.println("Enter height and base:");

                  float h=s.nextFloat();

                  float bs=s.nextFloat();

                  float art=0.5f*h*bs;

                  System.out.println("Area:"+art);

                  break;

        default: System.out.println("Wrong choice");

       }

  }

}

Read more on Brainly.in - https://brainly.in/question/10919614#readmore

Similar questions