Results 1 to 4 of 4
  1. #1
    carman12 is offline Member
    Join Date
    Dec 2010
    Rep Power

    Default Testing for single string in IF

    I'm running a program and a part of it requires the user to enter Y/N to a question can anyone tell me if this test method is even the slightest bit correct for conducting such a test...

    public static boolean isAnswer(String p){
    return true;
    return false;
    }//close if-else statement
    }//close isAnswer method

    I'm simply testing true or false whether the user entered Y to continue the loop of the program or to end it. Thanks alot.

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Rep Power


    Don't use == to compare strings; this compares object references, not the content of the string. Use the equals() method:
    Java Code:
    if(p.equals("Y")) ...

  3. #3
    carman12 is offline Member
    Join Date
    Dec 2010
    Rep Power


    IRON LION, thanks much bro...
    That's exactly what I was missing, i'm suprised though I missed something simple as that but I guess when you're deep in heavy code sometimes the small things miss us.

    Thanks again pal...

  4. #4
    Vase is offline Member
    Join Date
    Jan 2011
    Gainesville, FL
    Rep Power

Similar Threads

  1. Testing if it is an Int and if not ask again
    By Alexander_003 in forum New To Java
    Replies: 2
    Last Post: 11-27-2010, 12:09 AM
  2. how to change a single index of a string
    By ftrengnr in forum New To Java
    Replies: 5
    Last Post: 11-26-2010, 04:08 AM
  3. Replies: 2
    Last Post: 03-27-2010, 07:22 PM
  4. Splitting single string into array elements
    By phil128 in forum New To Java
    Replies: 11
    Last Post: 01-12-2009, 11:51 AM
  5. Testing EMF models.
    By manik_jforum in forum Eclipse
    Replies: 0
    Last Post: 12-10-2008, 08:59 AM

Posting Permissions

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