KnowledgeBoat Logo
|

Computer Applications

int a = 20, b=15; 
if ( a > 10 )
{
    a = a++; 
    b++;
}
System.out.println( a + ","	+ b);

What will be the values of a and b when executed?

Java

Input in Java

15 Likes

Answer

20,16

Working

The value of a is 20 and b is 16. The condition (a > 10) is true, so the execution enters the if block. The statement a = a++; increments the value of a by 1 after the assignment. So a remains unchanged as we are assigning the original value of a (which is 20) back to a. The value of b is incremented by 1 so b becomes 16.

Answered By

8 Likes


Related Questions