Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please, modify the code below to use the Switch Statements in Java instead of if statements to make the decisions. import java.util.Scanner; public class Area
Please, modify the code below to use the Switch Statements in Java instead of if statements to make the decisions. 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)); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started