+ 2

what the line sum+= do?

23rd Jul 2016, 5:12 PM
Emad Taheri
Emad Taheri - avatar
4 ответов
+ 2
No it's not like that.... look... if you are writing ' int sum=0; sum+=3; //that means.: sum=sum + 3; //sum=0+3; I.e. sum = 3 ( sum will get new value as 3) whatever the answer comes it will be stored into the sum again and sum will get new value as an answer.
23rd Jul 2016, 7:40 PM
Kaivalya Dalvi
Kaivalya Dalvi - avatar
+ 2
sum+= x; is the same like sum = sum + x; You can also use: -=, /=, *=, %=
23rd Jul 2016, 7:40 PM
FreakManMega
+ 2
Ok 😂
23rd Jul 2016, 7:43 PM
Petar Suvajac
Petar Suvajac - avatar
0
it's same as sum=sum+ example: int sum=0, sum+=3; System.out.print(sum); //3
23rd Jul 2016, 5:23 PM
Petar Suvajac
Petar Suvajac - avatar