0
Can spomebosy tell me why the result is 58, can anybody give me the math equation?
int [ ] myArr = {6, 42, 3, 7}; int sum=0; for(int x=0; x<myArr.length; x++) { sum += myArr[x]; } System.out.println(sum); // 58
3 odpowiedzi
+ 11
0 + 6 + 42 + 3 + 7 = 58
+ 8
Because the sum of all arrays elements is 58
+ 1
// when x = 0, myArr[x] = 6
// when x = 1, myArr[x] = 42
// when x = 2, myArr[x] = 3
// when x = 3, myArr[x] = 7
sum = 0
sum = sum + 6 +42 + 3 + 7
sum = 0 + 58