Java-Quiz: if, switch & Loops

This Java control flow quiz checks how if, switch, for, while and do-while really run. You will trace loops with break and continue, catch switch fall-through and spot loops that never end or run past an array.

Leicht 10 Fragen ~5 Minuten Bestanden ab 80% Java 17

Modus wählen

Du spielst als Gast: Melde dich an, damit XP und Serie gespeichert werden.

Beispielfrage

Frage 1 von 10

What does this print?

public class Main {
    public static void main(String[] args) {
        int day = 2;
        switch (day) {
            case 1: System.out.print("A");
            case 2: System.out.print("B");
            case 3: System.out.print("C");
                break;
            default: System.out.print("D");
        }
        System.out.println();
    }
}
Lösung zeigen

C. BC The switch jumps to case 2 and then falls through into case 3 because there is no break after B. The break after C stops it before default.

Darum geht es in diesem Quiz

  • Classic switch fall-through and break
  • Switch expressions with ->
  • for, enhanced for, while and do-while
  • break and continue
  • Common bugs like off-by-one and infinite loops

Häufige Fragen

Brauche ich ein Konto?

Nein. Jeder kann spielen. Mit Anmeldung werden XP, Serie, Abzeichen und Verlauf gespeichert.

Kann ich es wiederholen?

Ja. Dein Bestwert bleibt erhalten, und Fragen und Antworten werden jedes Mal neu gemischt.