File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Starting Java

 
Richard Maxwell
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 825
5
Java Python Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Richard Maxwell
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 825
5
Java Python Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 47274
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic