This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Loop issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Loop issue" Watch "Loop issue" New topic

Loop issue

apollo abel
Ranch Hand

Joined: Mar 31, 2006
Posts: 32
Ok, i've been trying since like 2 days ago to solve this problem, but i havent been able to do so.
this is the error i get:

As you can see the game ends when i enter a number higher than the number of marbles. however, i dont want the game to end, i want it ask the question again, until the user enters a number thats is not greater than the number of marbles, and that is not greater than the number of marbles divided by 2.
this is the code i have so far, i've tried making a boolean method but it always escape the program, i want it to repeat the question:

this is the code i have so far:

thanks for the support
[ April 01, 2006: Message edited by: apollo abel ]
Paul Santa Maria
Ranch Hand

Joined: Feb 24, 2004
Posts: 236
To prevent the exception, you need something like this:

But the real problem is that you probably want to constrain numMarbles to some number between min and the number of marbles actually left. For example:

As far as exiting the loop - I confess I haven't looked carefully at your code. It can definitely be simplified ... but as far as I can tell, once you compute the random value and pcMarblesTaken correctly, then it looks like numMarbles should eventually go down to zero and the loop exit. So you should be OK...

'Hope that helps .. PSM
[ April 01, 2006: Message edited by: Paul Santa Maria ]

Paul M. Santa Maria, SCJP
apollo abel
Ranch Hand

Joined: Mar 31, 2006
Posts: 32
Ok, the code now its done - well not really, is not an efficient code -
here it is:

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Loop issue
jQuery in Action, 3rd edition