1 Attachment(s)
If statements not working as planned
I currently have a program that builds a table based on some file information. The table has four columns, red, yellow, blue, and green. If a certain file has the word green in it, then the file's name goes in the green column. Same goes for red, yellow etc. For some reason, it's putting everything in the green column.
The way my code is laid out, it appears that my comparison statements are ineffective. My else statement points to the green column, so perhaps it's not picking up on the other if statements.
I tried putting a print statement right before the if else block, and the colors are printing out as they should as strings. "red" should equal "red", but for some reason it's not recognizing that. The if else block is below, and I have attached more of the program if it may help.
Code :
if (colorName == "red"){
// column 0 is where red files go
int columnNum= 0;
//getEmptyCell searches for the first empty cell in a column
int rowNum=getEmptyCell(data, columnNum);
data[rowNum][columnNum] = s.substring(66);
}
else if(colorName == "yellow"){
// column 1 is where yellow files go.
int columnNum= 1;
int rowNum=getEmptyCell(data, columnNum);
data[rowNum][columnNum] = s.substring(66);
}
else if (colorName == "blue"){
//...
int columnNum= 2;
int rowNum=getEmptyCell(data, columnNum);
data[rowNum][columnNum] = s.substring(66);
}
else {
int columnNum= 3;
int rowNum=getEmptyCell(data, columnNum);
data[rowNum][columnNum] = s.substring(66);
}
Re: If statements not working as planned
Hello davidvee!
I guess colorName is a String. And you should use the String's equals() method instead the == operator when comparing Strings.
Hope this helps.
Re: If statements not working as planned
Quote:
Originally Posted by
andreas90
Hello davidvee!
I guess
colorName is a
String. And you should use the
String's equals() method instead the
== operator when comparing
Strings.
Hope this helps.
That fixed it thank you.