Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 106 - 2617_JSSPS_C-7
P. 106

    5           switch (dayNumber) {
                  6           case 1:

                  7               System.out.println("Today is Monday");
                  8               break;
                  9           case 2:

                  10              System.out.println("Today is Tuesday");

                  11              break;
                  12          case 3:
                  13              System.out.println("Today is Wednesday");

                  14              break;
                  15          case 4:
                  16              System.out.println("Today is Thursday");

                  17              break;
                  18          case 5:

                  19              System.out.println("Today is Friday");
                  20              break;
                  21          case 6:

                  22              System.out.println("Today is Saturday");
                  23              break;
                  24          case 7:

                  25              System.out.println("Today is Sunday");
                  26              break;
                  27          default:

                  28              System.out.println("Invalid day number");
                  29          }

                  30      }
                  31  }
                  After compiling the preceding program, run it twice and enter values 6 and 8. When you enter the value
                  6, the case 6 will be executed and the output “Today is Saturday” will be displayed on the terminal.

                            Premium Edition-VII
                    104

| 101 102 103 104 105 106 107 108 109 110 111 |