← Quiz: Test Design Techniques: all 10 questions
Quiz: Test Design Techniques · Question 5 of 10
What does this print? (code)
What does this print?
public class Main {
public static void main(String[] args) {
int wrong = 0;
boolean locked = false;
boolean[] pins = {false, true, false, false, false};
for (boolean ok : pins) {
if (locked) continue;
if (ok) { wrong = 0; } else if (++wrong == 3) { locked = true; }
}
System.out.println(wrong + " " + locked);
}
}
- A.4 true
- B.1 false
- C.3 true
- D.0 false
Answer & explanation
Correct answer: 3 true
The correct PIN resets the counter after the first wrong attempt; the next three wrong PINs reach 3 and lock the card.
Can you get the rest right without peeking?
Take the timed Quiz: Test Design Techniques quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →