0

Can someone tell me how to correct this?

for(int i = 0; i < 7; i ++) 
 {
  if(team.group.toys[i].getName().equalsIgnoreCase(name )
      {
        team.insert(team.group.toys[i].getDescrip());
         System.out.println("OK");
       }
}
System.out.println("Is not included.");

This is so simple that I cannot figure out what the problem is. I need "OK" to print if the getName() equals name. If they do not equal print "Is not included".

I normally don't have problems with this but I have swapped and tried everything, I know that is is something simple.

Thank you,

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by KimJack
0

Just to clarify the question, the printing of "Ok" part works fine if the match is found, but you don't want it to also print "not included"?

0
String result = "Is not included.";
for(int i = 0; i < 7; i ++) 
 {
  if(team.group.toys[i].getName().equalsIgnoreCase(name )
      {
        team.insert(team.group.toys[i].getDescrip());
        result = "OK";
        break;  // no reason to keep looking here
       }
}
System.out.println(result);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.