I'm encountering some unexpected error messages when I try to do without a compound assignment operator. Here's my code:
package samsExperiments; public class SamsArrays { public int getAverage(int[] arr) { int sum = 0; for(int x : arr) { sum + x = sum; (sum + x) = sum; sum += x; } } }
Line 8 error: "Syntax error on token "+", invalid AssignmentOperator"
Line 9 error: "The left-hand side of an assignment must be a variable"
What's wrong? Why does it see an addition symbol as an assignment operator, when the = sign is clearly on the right-hand side of the x variable? And since sum and x are obviously both variables, why is it saying they're not?