write a program to input choice (1 or 2) if choice is 1 print the area of a circle otherwise print the perimeter of circle accept the radius of circle from user
Answers
Answered by
3
I am writing the program in JAVA.
import java.util.Scanner;
public class Choice {
public static void main(String[] args) {
int a, r;
double A, P;
Scanner in = new Scanner(System.in);
System.out.println("Enter radius of circle");
r = in.nextInt();
System.out.println("Enter '1' for area of circle and '2' for perimeter");
a = in.nextInt();
in.close();
switch(a){
case 1:
A=3.14*r*r;
System.out.println("The area of the cirlce is " + A + " square units.");
break;
case 2:
P=2*3.14*r;
System.out.println("The area of the cirlce is " + P + " units.");
break;
default:
System.out.println("Please enter either 1 or 2.");
break;
}
}
}
import java.util.Scanner;
public class Choice {
public static void main(String[] args) {
int a, r;
double A, P;
Scanner in = new Scanner(System.in);
System.out.println("Enter radius of circle");
r = in.nextInt();
System.out.println("Enter '1' for area of circle and '2' for perimeter");
a = in.nextInt();
in.close();
switch(a){
case 1:
A=3.14*r*r;
System.out.println("The area of the cirlce is " + A + " square units.");
break;
case 2:
P=2*3.14*r;
System.out.println("The area of the cirlce is " + P + " units.");
break;
default:
System.out.println("Please enter either 1 or 2.");
break;
}
}
}
Answered by
1
Explanation:
Wow ....
..................
Similar questions