Skills101
← All practice quizzes

Quiz: Java Control Flow

5 questionsNo time limitPass: 60%+10 XP on first pass

Read input with Scanner, use arithmetic, logical and ternary operators, make decisions with if-else and switch, and repeat with for, while, do-while and for-each.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What does this print?

    public class Main {
        public static void main(String[] args) {
            int x = 3;
            int y = x++ + ++x;
            System.out.println(y);
        }
    }
    
  2. Question 2

    How many times does a do-while loop run if the condition is false at the start?

  3. Question 3

    What does this print?

    public class Main {
        public static void main(String[] args) {
            int n = 2;
            switch (n) {
                case 1: System.out.print("one ");
                case 2: System.out.print("two ");
                case 3: System.out.print("three ");
            }
        }
    }
    
  4. Question 4

    What does this print?

    public class Main {
        public static void main(String[] args) {
            int count = 0;
            for (int i = 0; i < 10; i += 3) {
                count++;
            }
            System.out.println(count);
        }
    }
    
  5. Question 5

    Which operator is the ternary operator?