• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Starting Java

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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")))
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic