DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Simple problem (http://www.daniweb.com/forums/thread112371.html)

KimJack Mar 5th, 2008 6:12 pm
Simple problem
 
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,

Ezzaral Mar 5th, 2008 6:17 pm
Re: Simple problem
 
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"?

Ezzaral Mar 5th, 2008 6:20 pm
Re: Simple problem
 
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);

KimJack Mar 5th, 2008 8:12 pm
Re: Simple problem
 
Thanks Ezzaral.


All times are GMT -4. The time now is 9:52 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC