Computer Science, asked by Anonymous, 3 days ago

wap in java to display menu for areas of different shapes and then calculate area of selected shape by asking for required information.

If anyone will give me correct answer then I will make him/her ans as brainliest, with multiple thanks and follow ​

Answers

Answered by anindyaadhikari13
8

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - Java. Here we have calculated the area of three shapes - Circle, Square and Rectangle. For an invalid choice, program is terminated.

import java.util.Scanner;

public class Brainly{

   public static void main(String args[]){

       Scanner sc=new Scanner(System.in);

       System.out.println("1. Area of rectangle.");

       System.out.println("2. Area of square.");

       System.out.println("3. Area of a circle ");

       System.out.println("Any other value - Exit.");

       System.out.print("\nEnter your choice: ");

       switch(sc.nextInt()){

           case 1:  

           double l,b;

           System.out.print("Enter the length of the rectangle: ");

           l=sc.nextDouble();

           System.out.print("Enter the breadth of the rectangle: ");

           b=sc.nextDouble();

           System.out.println("Area of the rectangle is: "+l*b+" square unit.");

           break;

           case 2:

           System.out.print("Enter the length of the side of the square: ");

           double s=sc.nextDouble();

           System.out.println("Area of the square is: "+s*s+" square unit.");

           break;

           case 3:

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

           double r=sc.nextDouble(),area;

           area=Math.PI*r*r;

           area=Math.round(area*100)/100.0;

           System.out.println("Area of the circle is: "+area+" square unit.");

           break;

           default: System.out.println("Program terminated.");

       }

       sc.close();

   }

}

See the attachment for outputs.

Attachments:

anindyaadhikari13: Thanks for the brainliest :)
Similar questions