Computer Science, asked by anish55, 1 year ago

Input length , breadth , side and radius . Calculate the area of a square , rectangle or circle according to user choice. ( java- switch case)

Answers

Answered by x2theGOAT
2
import java.io.*;
import java.lang.*;
import java.util.*;
public class Ach
{public static void main(String arg[])throws IOException
{int ch,a,b;
Scanner sc=new Scanner(System.in);
System.out.println(“Please enter the choice:\n1:Circle\n2:Square\n3:Rectangle”);
ch=sc.nextInt();
Switch(ch)
{case 1:
{float pi=3.14;
System.out.println(“Input the radius”);
a=sc.nextInt();
float area=pi*r*r;
break;}
case 2:
{System.out.println(“Input the length of a side”);
a=sc.nextInt();
int area=a*a;
break;}
case 3:
{System.out.println(“Input the length and breadth of the rectangle”);
a=sc.nextInt();
b=sc.nextInt();
int area=a*b;
break;}
default:
{System.out.println(“Please give a valid input”);}}
System.out.println(“The area of the chosen figure is:”+area);}}
Similar questions