Source of SwitchErrors.java


  1: //SwithchErrors.java
  2: 
  3: import java.util.Scanner;
  4: 
  5: public class SwitchErrors
  6: {
  7:         public static void main(String[] args)
  8:         {
  9:                 Scanner keyboard = new Scanner(System.in);
 10: 
 11:                 System.out.println("Key: 1=blue, 2=red, 3=green");
 12:                 System.out.print("Enter a number and I'll return ");
 13:                 System.out.print("the corresponding color: ");
 14:                 int number = keyboard.nextInt();
 15: 
 16:                 switch(number)
 17:                 {
 18:                         case 1:
 19:                                 System.out.println("You choose blue!");
 20:                                 break;
 21:                         case 2:
 22:                                 System.out.println("You choose red!");
 23:                                 break;
 24:                         case 3:
 25:                                 System.out.println("You choose green!");
 26:                                 break;
 27:                         default:
 28:                                 System.out.println("Color not available!");
 29:                                 break;
 30:                 }
 31: 
 32:         }
 33: }