if (remainder == 10) { hexDigit = "A"; } else if (remainder == 11) { hexDigit = "B"; } else if (remainder == 12) { hexDigit = "C"; } else if (remainder == 13) { hexDigit = "D"; } else if (remainder == 14) { hexDigit = "E"; } else if (remainder == 15) { hexDigit = "F"; } else { hexDigit = "Error"; } |
switch (remainder) { case 10: hexDigit = "A"; break; case 11: hexDigit = "B"; break; case 12: hexDigit = "C"; break; case 13: hexDigit = "D"; break; case 14: hexDigit = "E"; break; case 15: hexDigit = "F"; break; default: hexDigit = "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: hexDigit = "" + remainder; break; case 10: hexDigit = "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; }
! (age >= 65 && income < 20000)
Since there are three simple statements there are 8 possible combinations of truth values in the truth table. However these statements are related so not all 8 combinations are possible. For example, if p is true (that is the year is divisible by 400) then q and r must also be true (a number divisible by 400 is also divisible by 100 and is divisible by 4). Similarly if q is true r must also be true since a number divisible by 100 is also divisible by 4. Complete the truth table below indicating whether or not a particular row in the table is possible. If it is give a date that satisfies the condition (for example if p, q, and r are all three true then one example would be 1600 because it is divisble by 400, by 100, and by 4).
Year divisible by 400 100 4 Possible? Example Year p q r T T T Yes 1600 T T F No (Not possible - if p is true r must be true) T F T ______ ____________ T F F ______ ____________ F T T ______ ____________ F T F ______ ____________ F F T ______ ____________ F F F ______ ____________