1. What will be the output of the program? 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 /
Ask Your Doubts Here
Comments
By: guest on 02 Jun 2017 01.26 am
This question is not testing your knowledge of the continue statement. It is testing your knowledge of the order of evaluation of operands. Basically 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. As the loop executes the comparison on line 4 will be: if(i > j) if(2 > 9) if(3 > 8) if(4 > 7) if(5 > 6) at this point i is not less than 5, therefore the loop terminates and line 9 outputs the values of i and j as 5 and 6 respectively. The continue statement never gets to execute because i never reaches a value that is greater than j.