+ 1
I am not sure what this line of code does?
sum += myArr[x];
2 Answers
+ 8
sum is a variable (you know that)
+= adds the second value to the first
myArr[x] is the value in the array at x (remember array values start from zero)
So sum += myArr[x]; adds the value of myArr at x to sum. The same, it adds the value that is the x+1 th term in the array myArr.
Example:
int sum = 4, x = 2;
myArr[2] = 7; //myArr needs to already be declared
sum += myArr[x];
System.out.print(sum);
/* Outputs 11 */
0
this line means the progarm will add all the elements of an array
sum is a predefined variable who's objective is to hold the value of the result
sum = sum + myArr[x]