2015 Practice Exam MCQ: 34/39

Test Corrections:

  1. Generate random value of number cubes
  • Original Answer: D. Correct Answer: E. Math.random() generates a number between 0 and 1, 1 exclusive. By multiplying Math.random() by 6 and adding 1 to it, we are able to generate a number between 1 and 6, both inclusive.
  1. showMe method with int parameter
  • Original Answer: C. Correct Answer: A. The showMe method calls itself recursively until arg is equal to 10 (It calls itself with a value that is one more than arg each iteration). The recursion ends when the method prints out "10."
  1. Loop that prints nothing
  • Original Answer: A. Correct Answer: E. In condition 1, nothing will print out since the base case is already not satisfied. In condition 2, the initialized value of x is not even so nothing will be printed. In condition 3, since x starts off as 1 and always increments by 2, nothing will be printed since x is never even.
  1. Methods start and changeIt aliases
  • Original Answer: C. Correct Answer: E. In this case, the changeIt method creates copies of the parameters, instead actually changing the values of them. Since we are referencing the original variable names, the original variable values will be printed instead of the values of the new variables.