🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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);
    }
}
  1. A.4 true
  2. B.1 false
  3. C.3 true
  4. 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 →