System.out.println("Enter size box you want"); int boxSize = scan.nextInt(); double price;
if (remainder == 10) { place0 = "A"; } else if (remainder == 11) { place0 = "B"; } else if (remainder == 12) { place0 = "C"; } else if (remainder == 13) { place0 = "D"; } else if (remainder == 14) { place0 = "E"; } else if (remainder == 15) { place0 = "F"; } else { place0 = "Error"; } |
switch (remainder) { case 10: place0 = "A"; break; case 11: place0 = "B"; break; case 12: place0 = "C"; break; case 13: place0 = "D"; break; case 14: place0 = "E"; break; case 15: place0 = "F"; break; default: place0 = "Error"; } |
A few things to note about switch statements:
switch (remainder) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: place0 = "" + remainder; break; case 10: place0 = "A"; break; case ... ... the rest is as above }
System.out.println("Enter size box you want"); int boxSize = scan.nextInt(); double price; if (boxSize == 10) { System.out.println("Small"); price = 2.5; } else if (boxSize == 20) { System.out.println("Medium"); price = 3.75; } else if (boxSize == 30) { System.out.println("Large"); price = 5.0; } else { System.out.println ("Not a valid size."); price = -1; } if (price > 0) System.out.println("Price is $" + price); else System.out.println("Sorry, we don't have that size");
if(total == MAX) if(total < sum) System.out.println("total == MAX and sum total < sum"); else System.out.println("total is not equal to MAX");
! (age >= 65 && income < 20000)