+ 2
Can anyone explain this code? ( Mainly - {sum += myArr[x]; )
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 Answers
+ 12
it simply sums up elements of that int array
//starting from index 0 to lengthOfArray-1 [in loop]
//sum+=x => sum=sum+x
+ 7
welcome ,
statements execute from top to bottom available in block of main method()
+ 2
Ohkk..Now I understand. But, tell me one last thing- The execution process of the statements .
Means which statement will be executed first, then second and so on..
Thanks for answering.