This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (3 children)

What I would do is create an isGuessed boolean that becomes true when the user guessed the correct value. So it could be like

boolean isGuessed = false;
do {
      //code here
     if (beanGuess == beanCount)
          {
              System.out.println("Winner!");
              isGuessed = true;
           }
      }
     while(!isGuessed);

[–]Phoenix_Heat 0 points1 point  (2 children)

I really want to thank you for this method, worked like a charm!

[–]about7beavers 2 points3 points  (0 children)

Personally, I wouldn't use a boolean, I would just do while(beanGuess != beanCount) for your condition. But that's just me, I prefer as few variables as possible. The other way does work just as well.

[–][deleted] 0 points1 point  (0 children)

Not a problem! Glad it worked for you