3.11. Medium Multiple Choice QuestionsΒΆ

These problems are similar to those you will see on the AP CS A exam.

    3-10-1: Which of the following would be the correct result from the following expression: 123 (decimal) - 12 (octal) + 111 (binary)?
  • 222
  • That would be the answer if these were all decimal values, but they are not.
  • 120
  • 12 in octal is 10 in decimal and 111 in binary is 7 in decimal so this is 123 - 10 + 7.
  • 118
  • This would be the answer if it was 123 - 12 + 111 (binary) but the 12 is in octal.
  • 121
  • Remember that the rightmost digit in any base is the base to the 0th power which is 1.
  • 214
  • Remember that the 111 is in binary (base 2). Its decimal value is 7.
    3-10-2: What will be printed by System.out.println(Integer.MAX_VALUE + 1);?
  • 2147483647
  • This would be true if it was printing just the maximum integer value.
  • 0
  • This might make sense, but adding one to the maximum integer value gives the minimum integer value.
  • There will be a compile time error
  • It will compile, but what will it do when you run it?
  • -2147483648
  • Adding one to the maximum integer value gives the minimum integer value due to overflow.
  • There will be a run time error
  • This makes sense, but it is not what happens.
Next Section - 3.12. Hard Multiple Choice Questions