What will be the result of compilation and execution of the following code:

public class Main {
    public static void main (String []args) {
        int i = 0;
        i += i++;
        System.out.println(i);
    }	
}
Explanation
JLS $15.7.1. Compound assignment operator is equivalent to i = i + i++ and is executed accordingly.
i will be incremented after evaluating the expression but before the assignment.

Слідкуй за CodeGalaxy

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

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