0

What is the output of this code?? With explanation

Int a=8; a+=++a; System.out.println(++a);

20th Apr 2017, 4:57 AM
Basha Syed
Basha Syed - avatar
4 Respuestas
+ 16
int a = 8; a+=++a; // 8 = 8 + 9 after this a is 17 System.out.println(++a); // output 18
20th Apr 2017, 5:06 AM
Tashi N
Tashi N - avatar
+ 2
if you put System.out.print(a++) instead, would it be 17?
20th Apr 2017, 5:46 AM
Jeremy Hunter
Jeremy Hunter - avatar
+ 2
Yeah, it prints 17 and then a becomes 18
20th Apr 2017, 5:59 AM
Basha Syed
Basha Syed - avatar
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.
20th Apr 2017, 11:18 AM
Sumit Kale
Sumit Kale - avatar