Write a Java program for
Answers
Question:-
Write a menu driven program to perform the following tasks:-
i) Area of a circle(A = πr^2)
ii) Area of a rectangle(A=length*breadth)
iii) Exit from the program.
Program:-
import java.util.*;
class Java
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("1. Area of a circle. ");
System.out.println("2. Area of a rectangle.");
System.out.println("3. Exit. ");
System.out.print("Enter your choice: ");
int c=sc.nextInt();
switch(c)
{
case 1:
System.out.print("Enter radius: ");
double r=sc.nextDouble();
r=Math.PI*r*r;
System.out.println("Area is: "+r);
break;
case 2:
System.out.print("Enter length: ");
double l=sc.nextDouble();
System.out.print("Enter breadth: ");
double b=sc.nextDouble();
l*=b;
System.out.println("Area is: "+l);
break;
case 3:
System.exit(0);
break;
}
}
}