0
What is the output of this code?? With explanation
Int a=8; a+=++a; System.out.println(++a);
4 ответов
+ 16
int a = 8;
a+=++a; // 8 = 8 + 9 after this a is 17
System.out.println(++a); // output 18
+ 2
if you put System.out.print(a++) instead, would it be 17?
+ 2
Yeah, it prints 17 and then a becomes 18
0
int a=8; // a is a variable which is of type integer.
a+=++a; //remember, right side execute first in any expression. in this example, ++a=9. now a+=b equals to a=a+b.
a+=++a; //equals 17
now variable a is updated wih new value that is 17.
when you use system.out.print, it prints on console.
System.out.println(++a); // a incremented i.e 18.