• 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

Loop Structures

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am very new to Java so please bare with me. I am writing a program that calculates court fines. At the end of the application I need to insert some code that will ask the user if they would like to continue at this point I need to invoke a loop if the answer is y finish if the answer is n. I have tried the while(!done) method I have tried IF ELSE (I have tried a lot of stuff). The variable I am using for the users answer of yes or no is String repeat; my boolean variable is boolean done = flase; From what I can tell the Boolean done = false is staying false for either choice. How can I get the repeat variable to yes or no to change the boolean done to true? I am taking on line classes and my instructor answer was to check Google.com s I could use anyones help at this point.
Thank you in advance for your assistance.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are reading the user input from System.in then the problem maybe because System.in.read returns the user entered text+Carriage return + linefeed (in windows, in unix it will have text+ CR). Hence you need to discard these before using the input string for comparison.
check out the example below:

hope this helps...
 
Michael Steen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the input.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic