I try to learn Java and have a question. I created a class Color. This class contains an constructor for "color" with 3 int values (red, green, blue). Then I have an array with a lot of color elements.
Now I want to add 4 of this elements to one and divide it, so I get the average of each int value.
But eclipse says, that the operator + is undefined.
Color sum = new Color(red, green, blue)
for (int i = 0; i < length; i ++) {
sum = sum + array[i];
}
public Color(int r, int g, int b){
this.red=r;
this.green=g;
this.blue=b;
}
How can I add the values of each array element to a sum? The elements in the array are from the type color.
string
what should java do ? You have to sum the red,green,blue values manually – Omar Aflak