I am trying to have different things happen depending on what digit is called in an array–in this case, different colored lines. I am not sure how to code the if statement to recognize a particular digit. This is what I have now:
int[] data = {1, 2, 3, 4, 5};
background(#1CB9FF);
ellipse (10*data[0], 10*data[1], 20, 20);
for (int i=0; i<data.length; i++) {
if (data[i].equals('2')) {
stroke(255);//white line
line(data[i], 0, data[i], 100); }
else if (data[i].equals('3')) {
stroke(#FC0824);//red line
line(data[i], 0, data[i], 100); }
else {
stroke(0);//black line
line(data[i], 0, data[i], 100); }
}
When I try to run this code, I get the following error message:
“Cannot invoke equals(char) on the primitive type int”
When I get rid of the apostrophes around the numbers:
int[] data = {1, 2, 3, 4, 5};
background(#1CB9FF);
ellipse (10*data[0], 10*data[1], 20, 20);
for (int i=0; i<data.length; i++) {
if (data[i].equals(2)) {
stroke(255);//white line
line(data[i], 0, data[i], 100); }
else if (data[i].equals(3)) {
stroke(#FC0824);//red line
line(data[i], 0, data[i], 100); }
else {
stroke(0);//black line
line(data[i], 0, data[i], 100); }
}
…I get the error:
“Cannot invoke equals(int) on the primitive type int”
Help!