Results 1 to 6 of 6
  1. #1
    maynn123 is offline Member
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Default If statement problem

    Hello,
    I have encountered a problem in which when I input "Eagle", and then "Eagle" as the answer it comes out as "Correct". However, when I input "Bear" and "Eagle" as the answer it still comes out as "Correct".
    Could anyone tell me how to fix this? Thanks and waiting for a reply.
    Here is the code;

    String newWord = "";
    String userWordGuess = "";

    console.println("The new word?");
    newWord = console.readLine();
    console.println("Your guess?");
    userWordGuess = console.readLine();
    if (userWordGuess != newWord){
    console.println("CORRECT");
    } else {
    console.println("INCORRECT");
    }

    }
    Last edited by maynn123; 11-27-2012 at 08:14 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,926
    Rep Power
    8

    Default Re: If statement problem

    You're going to have to copy and paste your code as an SSCCE if you want somebody to help you with it.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    Default Re: If statement problem

    I'm psychic and through the cosmic mists of time and space I can see a == operator.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default Re: If statement problem

    Well, I can see a '!=' operator...:)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: If statement problem

    And I see it prints "CORRECT" for !=

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

    Default Re: If statement problem

    Hrmph ... I have to put new batteries in my crystal ball ...

    kind regards,

    Jos (<--- clairvoyant, but not when sober)
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. problem with if statement?
    By cherrychives in forum New To Java
    Replies: 6
    Last Post: 04-25-2012, 02:42 AM
  2. sql statement problem
    By vincentcharrie in forum Eclipse
    Replies: 5
    Last Post: 02-16-2012, 03:41 PM
  3. Problem with if statement
    By SiX in forum New To Java
    Replies: 8
    Last Post: 07-22-2011, 07:49 PM
  4. If-Else statement problem
    By MomenT in forum New To Java
    Replies: 9
    Last Post: 10-23-2008, 08:06 AM
  5. Please help me with this Problem Statement
    By KMS in forum New To Java
    Replies: 1
    Last Post: 09-22-2008, 08:44 PM

Posting Permissions

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