← 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);
}
}
- A.7
- B.8
- C.6
- 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 →