Question: import java.util.Scanner; public class Area { public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.print(Enter code(C for circle, R for rectangle, S
import java.util.Scanner;
public class Area {
public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.print("Enter code(C for circle, R for rectangle, S for square): "); char code = in.next().charAt(0);
if(code == 'C') { System.out.print("Enter radius: "); double radius = in.nextDouble(); System.out.println("Area of circle is " + (Math.PI * radius * radius)); } else if(code == 'R') { System.out.print("Enter width: "); double width = in.nextDouble(); System.out.print("Enter height: "); double height = in.nextDouble(); System.out.println("Area of rectangle is " + (width * height)); } else { System.out.print("Enter length of side: "); double side = in.nextDouble(); System.out.println("Area of square is " + (side * side)); } } }
- Change the program so that it loops back around to ask the user to enter another figure. This loop will keep asking the user over and over again. Once the user enters an X, the loop will end.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
