🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Control Flow: all 10 questions

Quiz: Java Control Flow · Question 1 of 10

What does this print? (code)

What does this print?

public class Main {
    public static void main(String[] args) {
        int x = 3;
        int y = x++ + ++x;
        System.out.println(y);
    }
}
  1. A.7
  2. B.8
  3. C.6
  4. D.9
Answer & explanation

Correct answer: 8

x++ gives 3 (x becomes 4), then ++x makes x 5 and gives 5. 3 + 5 = 8.

Can you get the rest right without peeking?

Take the timed Quiz: Java Control Flow quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →