Return to site

☕➿ JAVA CERTIFICATION LOOP: can you find the OUTPUT in 20 seconds?

It looks easy. That is usually when Java certification questions bite. 😈

· java

🔸 TLDR

You have 20 seconds. ⏱️

What does this Java code print?

public class Quiz {
    public static void main(String[] args) {
        int i = 0, sum = 0;
        outer: do {
            if (i++ == 2) continue outer;
            sum += ++i;
        } while (i < 5);
        System.out.println(i + ":" + sum);
    }
}
Section image

No IDE.

No debugger.

No running the code. 👀

Just trace it like you would during a Java certification exam.

This tiny question combines:

▪️ i++ — use the value, then increment

▪️ ++i — increment first, then use the value

▪️ do-while — the body executes before the condition is checked

▪️ continue outer — jump directly to the loop condition

⏱️ Target time: 20 seconds

🔸 TAKEAWAYS

▪️ Never treat i++ and ++i as interchangeable.

▪️ With continue, check exactly where execution resumes.

▪️ In certification questions, trace variables statement by statement.

▪️ Tiny loops can test much more than loop syntax.

What does it print? 👇

#Java #JavaCertification #OCPJava #Java25 #JavaQuiz #JavaDeveloper #Programming #CodingChallenge #JavaProgramming

🙋‍♂️Answer: "5:7"

Go further with Java certification:

Java👇

Spring👇

SpringBook👇

JavaFullstackBook👇