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.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Зарегистрируйся сейчас
или Подпишись на будущие тесты