Build a program that takes an int from to and prints the corresponding day of the week. Use both the classic switch and the arrow switch so you can compare them side by side.
Classic version:
int day = 4;
switch (day) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
break;
case 6:
System.out.println("Saturday");
break;
case 7:
System.out.println("Sunday");
break;
default:
System.out.println("Invalid day");
}
Now rewrite it with arrow syntax. Then try the expression form: assign the day name to a String variable using a switch expression with ->, and print it afterward. Notice how much shorter the expression version is.