What will the program bring to the console?

public class Test {
    public static void main(String[] args) {
        boolean b = true;
        int x = 0;

        do {
            if (x++ > 5)
                b = false;
        } while (b);
It is obvious that the numbers on the screen will be displayed sequentially. It remains only to find out what number will be displayed the first, and witch one the last.
Since at each test the condition of the variable x increases then 1 will be the first number to be printed.
At the last iteration of the condition x++ > 5 must become true. Since the value of the expression x++ is the original value of the variable, it will be at x = 6. But on the screen will be displayed a new larger value, ie, 7.
We'll get the answer: 1234567.

Слідкуй за CodeGalaxy

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

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