import java.time.*; public class Test2 { public static boolean swStmt(int X) { boolean Res = false; System.out.print("Switch statement ... "); switch(X) { case 1,2,3, // multiple cases can be combined // no 4, 5,6 -> Res = true; // Control transfers to the end of the switch block. case 7,8 -> Res = false; }; return Res; } public static boolean swExpr(int X) { System.out.print("Switch expression ... "); return switch(X) { case 1,2,3, // multiple cases can be combined // no 4, 5,6 -> true; // Control transfers to the end of the switch block. case 7,8 -> false; default -> true; }; } public static void main(String[] args) { int Failvalue = 4; int Goodvalue = 5; System.out.println("int completeness ... "); try { swExpr(Failvalue);System.out.println("checked statically "); } catch (Exception E) { System.out.println("raised " + E.getClass().getName()); } try { swStmt(Goodvalue); System.out.println("no run-time completness check!"); } catch (Exception E) { System.out.println("raised " + E.getClass().getName());} try { swStmt(Failvalue); System.out.println("FALL THRU!!!"); } catch (Exception E) { System.out.println("raised " + E.getClass().getName());} } }