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

30th Nov 2017, 1:53 PM
CĂ©sar Rivera
CĂ©sar Rivera - avatar
3 Answers
+ 11
0 + 6 + 42 + 3 + 7 = 58
30th Nov 2017, 2:23 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 8
Because the sum of all arrays elements is 58
30th Nov 2017, 2:02 PM
Vukan
Vukan - avatar
+ 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
30th Nov 2017, 4:49 PM
#RahulVerma
#RahulVerma - avatar