Results 1 to 5 of 5
  1. #1
    00sonthuy00 is offline Member
    Join Date
    Nov 2013
    Posts
    3
    Rep Power
    0

    Unhappy Help : i want a String with either "true" or "false" in it?

    i try a String with either "true" or "false" in it, but it don't ?

    Java Code:
                        System.out.print("Enter id: ");
                        String id = input.next();
                       
                        System.out.println("Removing Student ?? (Y/N)");
                            boolean answer = std.removeStudent(id);
                           
                            String question = new String().valueOf(answer);
                            if (question.equals("y")) {
                                std.removeStudent(id);
                                break;
                            }
                            else 
                                if(question.equals("n"))
                            {
                                break;
                            }

    why? so what should I do?

    please help

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default Re: Help : i want a String with either "true" or "false" in it?

    It seems that you want either a "y" or "n" for an answer; read a String and check its value against those two values ... or am I missing something here?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    00sonthuy00 is offline Member
    Join Date
    Nov 2013
    Posts
    3
    Rep Power
    0

    Default Re: Help : i want a String with either "true" or "false" in it?

    sorry, My language skills are weak :(

    I enter a string is "id" and want to delete it, when you enter "y", the command will delete operation, when I enter "n" will not erase that return
    Last edited by 00sonthuy00; 11-01-2013 at 06:33 PM.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default Re: Help : i want a String with either "true" or "false" in it?

    Forget about that "id" String for now; suppose you have a String named answer; you can compare it as follows: answer.equals("y") or answer.equals("n"); the result of that method call is a boolean value; either true or false. You should build your logic around it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    00sonthuy00 is offline Member
    Join Date
    Nov 2013
    Posts
    3
    Rep Power
    0

    Default Re: Help : i want a String with either "true" or "false" in it?

    thank u :)

Similar Threads

  1. Replies: 0
    Last Post: 12-07-2012, 09:29 AM
  2. Replies: 3
    Last Post: 10-30-2012, 04:06 PM
  3. Replies: 14
    Last Post: 04-08-2011, 07:01 PM
  4. Replies: 2
    Last Post: 01-24-2009, 07:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 08:35 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
  •