What happens when the following class is compiled and executed?

public class VerySimpleClass {
  public static void main(String... args) {
     for (byte i = 6, j = 0 ; (j += i++) <= 10; i >>= 1, System.out.print(--j));
Code will be compiled successfully since given form of the for loop is syntactically correct and does not contain errors. However, the program will fall into an infinite loop, because the value of the j is not growing and at the point of loop continuation condition check the variable j will always be equal to 1.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes