What will be the output of the given Java unary operators related code snippet?

 

int i = 1, j = 10; 
do 
{
    if(i++ > --j) /* Line 4 */
    {
        continue; 
    } 
} while (i < 5); 
System.out.println("i = " + i + "and j = " + j); /* Line 9 */


The answer will be : i = 5 and j = 6
The prefix and postfix unary operators have a higher order of evaluation than the relational operators. So on line 4 the variable i is incremented and the variable j is decremented before the greater than comparison is made. The continue statement never gets to execute because i never reaches a value that is greater than j.

 


Related #tags:     #java     #core-java    

Related questions




Looking for change? Click below to prepare for technical interview.


Technical Interview Questions