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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 61092
    
  66

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: 61092
    
  66

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: 7696
    
  20

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
 
wood burning stoves
 
subject: What is the best way to get my program to repeat itself?