Ian,
You are suffering from the dreaded double equal comparison of String objects. If you look in the API many, if not most or all, of the object comparisons are done with a method, such as with the case of String using the String.equals() method you can look up in the API. The "==" operator comparison looks and says: "is this variable and that variable contain the same value. Well, in the case of String, an object, it does not because it is a reference to a String who's value is stored someplace in the
Java references. So you will never get the case where "My String" == new String("My String") come evaluate to true, they simply reference different objects. The same is true when you read in the value from your scanner object, you're getting a new String when you do, so it will never evaluate to equal in a comparison using the double equals operator.
Les
Ian Tail wrote:Hi, I can't work out why my if statement won't pass?