Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1. Understand how verbal and nonverbal communication differ.

Answered: 1 week ago