KnowledgeBoat Logo

Computer Applications

What will be the output of the following code?

int num = 10; 
if (num < 20)
    System.out.print(num++);
else
    System.out.print(--num);

Java Conditional Stmts

3 Likes

Answer

Output
10
Explanation

Since the condition (num < 20) is true, the if block is executed. Postfix operator first uses the value and then increments the value, so the value of num is first printed (10) and then incremented.

Answered By

3 Likes


Related Questions