Why x++ before adding sum += ... ?? Thought it starts with zero not with one? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why x++ before adding sum += ... ?? Thought it starts with zero not with one?

..

15th Dec 2017, 12:20 PM
PhoenixPlay
7 Answers
+ 8
if you have sum += x++; than it's ok because x++ eveluate exspression and then increment value. In other case this will work good: sum += x; x++;
15th Dec 2017, 12:38 PM
Vukan
Vukan - avatar
+ 2
don't want other languages but ty
15th Dec 2017, 12:28 PM
PhoenixPlay
+ 2
ooooooooohhhhhh thank you 😊
15th Dec 2017, 9:32 PM
PhoenixPlay
0
int [ ] myArr = {6, 42, 3, 7}; int sum=0; for(int x=0; x<myArr.length; x++) { sum += myArr[x]; } System.out.println(sum);
15th Dec 2017, 1:07 PM
PhoenixPlay
0
that's the program I have
15th Dec 2017, 1:08 PM
PhoenixPlay
0
and there i have X++ and then sum+=myArr[X]
15th Dec 2017, 1:08 PM
PhoenixPlay
0
okay why isn't it at that point??
15th Dec 2017, 4:45 PM
PhoenixPlay