Well let me confuse you a little bit more. Because Strings are Objects, they have methods that will allow you to do this checking that you want.
The one method that will do you wonders in this case is the equalsIgnoreCase() method. You can check it out in the Java api yourself if you want:
http://java.sun.com/j2se/1.5.0/docs/api/ja...ang/String.htmlBecause this method already returns a boolean value, you can use it directly in your return statement.
This may come off as a little confusing initially, but just bear with it:
CODE
public static boolean isYorN(String str)
{
return str.equalsIgnoreCase("y") || str.equalsIgnoreCase("n");
}
When the code:
str.equalsIgnoreCase("y")
is called, it is comparing whatever value you have in the variable str, and it is trying to determine if it is equal to "y" or "Y". If neither of these are correct, then the statement after the or operator (this thing -> ||) is read:
str.equalsIgnoreCase("n")
in the same way, this code determines whether the value in str is either "n" or "N".
Because both of these values return a boolean as a result, if the value in the variable str is "y", "Y", "n", or "N", then it will automatically return ture. Otherwise, the method will return false.