Results 1 to 2 of 2
  1. #1
    SeanC is offline Member
    Join Date
    Aug 2010
    Posts
    24
    Rep Power
    0

    Smile String/loop problem

    Hi, I'm having a problem with this part of my code:

    Java Code:
    } while ((menu2.equals("4") == false) || ((menu2.equals("3")) == false));
    The compiler seems to be ignoring it for me... is there something wrong? I basically want the loop to end if the String menu2 is either "4" or "3". What exactly am I doing wrong?

    Thanks :)

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    x.equals(y) is the same as x.compareTo(y) == 0.

    Remove the ==false part of the codes and try again. The "equals" method returns true if equal, false if not, whereas the compare functions are numeric based--0 if equal, positive if longer, negative if shorter.

Similar Threads

  1. Exiting a while loop using a String?
    By Isshin in forum New To Java
    Replies: 4
    Last Post: 02-22-2010, 12:33 AM
  2. exiting a while loop with a string
    By Aldius in forum New To Java
    Replies: 3
    Last Post: 12-10-2009, 11:38 PM
  3. String and while loop
    By Exception in forum Java Applets
    Replies: 5
    Last Post: 09-24-2009, 01:32 PM
  4. Using string to terminate loop
    By mrblippy in forum New To Java
    Replies: 3
    Last Post: 04-23-2009, 07:16 AM
  5. terminating a while loop with a string
    By tkdvipers in forum New To Java
    Replies: 3
    Last Post: 07-10-2007, 12:23 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •