| Author |
Starting Java
|
Richard Maxwell
Greenhorn
Joined: Jan 05, 2013
Posts: 3
|
|
Hello
I am teaching myself Java, I am brand new to Java, my friend recommend buy a book from amazon.
I am struck where it says I am suppose to change case.
Here is what i like to do. when a user enter a number it calculate and display and it ask do you want to continue I want the user to choose either lower or upper case Y or y or N or n.
Any help would be great
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 792
|
|
Welcome to the Ranch!
In order to get the most out of people in this community, you need to TellTheDetails, possibly with some code snippet that reflects what you are trying to do. Currently, I'm not clear on what the issue is exactly, but if you want to check for the user input ignoring the case (Y or y, or whatever) then you might want to check String#equalsIgnoreCase(String) method.
|
The quieter you are, the more you are able to hear.
|
 |
Richard Maxwell
Greenhorn
Joined: Jan 05, 2013
Posts: 3
|
|
Thank you kemal for response
Here is the code
As you can see the program will end by pressing any key, but I want program to end only when a user enter N or n
I am not sure if i should use not operator ( ! ) Or equalsIsIgnoreCase and I am not sure how to use it.
|
 |
Jayesh A Lalwani
Bartender
Joined: Jan 17, 2008
Posts: 1271
|
|
Richard,
Please use code tags while posting code. It makes it easier for others to read. I have done it for you this time
|
 |
Jayesh A Lalwani
Bartender
Joined: Jan 17, 2008
Posts: 1271
|
|
|
You can use the or operator|| to check for 2 conditions. a||b is true if either one of them is true
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 792
|
|
As you can see the program will end by pressing any key, but I want program to end only when a user enter N or n
Then you should think it this way: Repeat everything if the user did not enter N or n (in other words, the user can enter anything else). This is where the negation operation would be suitable.
|
 |
Richard Maxwell
Greenhorn
Joined: Jan 05, 2013
Posts: 3
|
|
Hey guys thank you kemal and Jayesh as per your suggestion I made the changes now it works.
String choice = "y";
String choices ="n";
while (!choice.equalsIgnoreCase("y") == (!choices.equalsIgnoreCase("n")))
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32645
|
|
Richard Maxwell wrote: . . . while (!choice.equalsIgnoreCase("y") == (!choices.equalsIgnoreCase("n")))
I suggest you work out what that means. It looks like a tautology to me.
|
 |
 |
|
|
subject: Starting Java
|
|
|