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,

Recommended Answers

All 3 Replies

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"?

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);

Thanks Ezzaral.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.