Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


How many times does the traffic light change colors in the loop?

  1. 5

  2. 6

  3. 7

  4. 8

The correct answer is: 7

The traffic light in the loop actually changes colors 8 times, not just 7. The reason for this is because there are four major colors that the light cycles through (red, yellow, green, and off), and there are two instances in which the light flashes red and off, making a total of eight color changes. It is important to carefully consider all factors and details given in the question when selecting your answer. A and B may seem like they could potentially be correct answers, but they do not account for the two instances of flashing red and off. D is too high of a number as it does not account for the off color.