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));
  }
}
Explanation
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.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Java
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести