[SOLVED] SOLVED:Switch Statement

10.00 $

Programming resource
Digital learning resource
Category:
Practical programming resource
Suitable for guided study and reference
Tutor guidance available when needed

Description

5/5 - (3 votes)

Switch Statement Open the provided file SwitchErrors.java. The Java source code is shown below. The program evaluates an integer entered by the user and displays the color assigned to the integer. Compile the program. The program has several syntax and logic errors. Fix the syntax errors and compile and run the program. Does the program run as you expected? Locate and correct the errors in the program logic. Be sure to make use of the debugger available in Eclipse to help identify errors. package edu.ilstu; import java.util.Scanner; public class SwitchErrors { public static void main(String[] args) { Scanner keyboard = new Scanner(System.out); System.out.println(“Key: 1=blue, 2=red, 3=green”); System.out.print(“Enter a number and I’ll return “); System.out.print(” the corresponding color. “); number = keyboard.nextInt(); switch(number) { case 1: System.out.println(“You chose red!”); break; case 2: System.out.println(“You chose blue!”); break; case 3: System.out.println(“You chose green!”); default: System.out.println(“Color not available!”); break; } } }

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.