Controlling Java Program Code - Quiz Explanation

The answers you selected are indicated below, along with text that explains the correct answers.
 
1. Each case match in a switch statement must be:
Please select the best answer.
  A. An integer
  B. A character
  C. A constant
  The correct answer is C. Each case match in a switch statement must be a constant, which is compared against the switch expression for a match. Any primitive Java data type can be used in a case match for a switch statement as long as it is constant.

2. Which one of the following loop components does the while loop utilize?
Please select the best answer.
  A. LoopCondition
  B. InitializationExpression
  C. StepExpression
  The correct answer is A. The while loop utilizes a loop condition to determine whether it executes a loop statement.for loops are the only loops that utilize initialization expressions and step expressions.


3. What differentiates a do loop from a while loop?
Please select the best answer.
  A. The loop condition of a do loop is executed before the loop statement.
  B. The loop condition of a do loop is executed after the loop statement.
  C. The loop statement of a do loop is sometimes never executed.
  The correct answer is B. The difference between a do loop and a while loop is that the loop condition of a do loop is executed after the loop statement. The loop statement of a do loop is always executed at least once.


4. What Java statement do you use to break out of a loop or branch?
Please select the best answer.
  A. break
  B. halt
  C. exit
  The correct answer is A. The break statement is used to break out of a branch or loop. There are no such Java statements as halt and exit.

5. What Java statement is used to skip to the next iteration of a loop?
Please select the best answer.
  A. skip
  B. continue
  C. break
  The correct answer is B. The continue statement is used to skip to the next iteration of a loop. There is no such Java statement as skip. The break statement is used to break out of a branch or loop.

Java Virtual Machine