Reputation: 18531
This works:
for(int i = 0; i < size; i++){
avg[0] = avg[0] + array0[i];
avg[1] = avg[1] + array1[i];
avg[2] = avg[2] + array2[i];
avg[3] = avg[3] + array3[i];
}
However, this doesn't:
for(int i = 0; i < size; i++){
avg[0] =+ array0[i];
avg[1] =+ array1[i];
avg[2] =+ array2[i];
avg[3] =+ array3[i];
}
In the second example, the array doesn't add to itself.
Upvotes: 2
Views: 197
Reputation: 44438
it's +=
, not =+
What you do could be valid code as well, but right now you're doing
avg[0] = + array0[i];
It will work for numeric types (which I assume you have). Simplified example without array index:
int x = +5;
Sample:
public static void main(String[] args) {
int x = -5;
int y = +x;
System.out.println(y); // - + => -
int a = 5;
int b = -a;
System.out.println(b); // + - => -
int c = 5;
int d = +5;
System.out.println(d); // + + => +
int m = -5;
int n = -m;
System.out.println(n); // - - => +
}
Output:
-5
-5
5
5
Copied from comments for clarity:
You're basically saying x = + y
. In this case the +
is just a matter of indicating it's a positive integer. It's valid code, but it's not what you intend.
Upvotes: 11