File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes What is the best way to get my program to repeat itself? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is the best way to get my program to repeat itself?" Watch "What is the best way to get my program to repeat itself?" New topic
Author

What is the best way to get my program to repeat itself?

J. Chris Miller
Ranch Hand

Joined: Sep 11, 2012
Posts: 30
Here is my program, how do I get it to repeat after it is finished printing?:



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Hint: loop


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
J. Chris Miller
Ranch Hand

Joined: Sep 11, 2012
Posts: 30
Bear Bibeault wrote:Hint: loop


I assumed you could use a while loop, but I'm unsure on the format, and I've tried several things. So, I'm still stuck.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Show, don't tell. Post your attempt.
J. Chris Miller
Ranch Hand

Joined: Sep 11, 2012
Posts: 30
Okay, I fooled around with the while loop and got it to work finally. Thanks!
J. Chris Miller
Ranch Hand

Joined: Sep 11, 2012
Posts: 30
Here's the updated code:

Sumit Bisht
Ranch Hand

Joined: Jul 02, 2008
Posts: 329

Hi Chris!
The only problem that I see in your code is that your loop has got no exit condition. It might be helpful to have a confirmation by the user at the end to continue with the execution or not and set the variable game correctly or have a special case such as anything other than 1-99 which will break from the loop.
As of now, only a ParseException will end the loop, which is not the best approach always.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7552
    
  18

J. Chris Miller wrote:Here's the updated code:...

Chris,

Please DontWriteLongLines. It makes your thread very hard to read. I've broken yours up this time, but for future reference, please remember:
80 characters max.
And that includes string literals and comments.

Thanks.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the best way to get my program to repeat itself?
 
Similar Threads
Recursion tracing help
Count the number of vowels, words, and sentences.
word switcher porlebm
Further problems with this program
converting this to a prefix instead of a postfix calculator