/* this compares case statements to if-else statements */ public class casestate { public static void main(String args[]) { ifDown(1, 10); caseDown(2, 10); ifDown(3,4 ); caseDown(9, 42); } public static void ifDown(int down, int yards) { if(down == 1) { System.out.println("First down!"); } else if(down == 2) { System.out.println("Second down and "+yards+"."); } else if(down == 3) { System.out.println("Third down and "+yards+"."); } else if(down == 4) { System.out.println("Turn over!"); } else { System.out.println("Error."); } } public static void caseDown(int down, int yards) { switch(down) { case 1: System.out.println("First down!"); break; case 2: System.out.println("Second down and "+yards+"."); break; case 3: System.out.println("Third down and "+yards+"."); break; case 4: System.out.println("Turn over!"); break; default: System.out.println("Error."); } } }