public class ClassicSwitchExample { public static void main(String[] args) { String day = "Monday"; String typeOfDay; switch (day) { case "Monday": typeOfDay = "Start of work week"; break; case "Friday": typeOfDay = "End of work week"; break; case "Saturday": case "Sunday": typeOfDay = "Weekend"; break; default: typeOfDay = "Midweek day"; break; } System.out.println(day + " is a " + typeOfDay); } }
public class EnhancedSwitchExample { public static void main(String[] args) { String day = "Monday"; String typeOfDay; typeOfDay = switch (day) { case "Monday" -> "Start of work week"; case "Friday" -> "End of work week"; case "Saturday", "Sunday" -> "Weekend"; default -> "Midweek day"; }; System.out.println(day + " is a " + typeOfDay); } }