What will be the output of the following code:

public class Main {
        public static void main (String []args) {
                 int z = 1;
                 z += z += z += z += z;
                 System.out.println(z);
        }       
}
Explanation
The initial value is used for z from left to right. Then expressions are evaluated from right to left. In other words, every expression z+=f(z) is the same as z = z+f(z), where all left summands are equal to 1. Therefore the result will be 1+1+1+1+1 = 5.

Слідкуй за CodeGalaxy

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

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