# While JOptionPane equal Yes????

• October 20th, 2010, 08:06 PM
maximus20895
While JOptionPane equal Yes????
I want the while at the end to say while JOption says yes. Meaning when asked if they want to play again it will re loop and play it again if they click yes. I have looked and I can't find how to do it. I also used an "int" which was selection, but it says i need a boolean value which kinda makes sense but I dont know how..

Thanks

Code :

```package lab3;   // Import import java.util.Scanner; import javax.swing.JOptionPane;   // Start public class Problem4 { public static void main (String[] args){ // It's time to play the lottery! int selection;     do{ int lottery = (int)(Math.random() * 1000);   int runAgain;     // Promt the user to enter a guess Scanner input = new Scanner(System.in); System.out.println("Enter your lottery pick (three digits): "); int guess = input.nextInt();   // Get digits from lottery int lotteryDigit1 = lottery / 100; int lotteryDigit2 = lottery / 10; int lotteryDigit3 = lottery % 10;   // Get digits from guess int guessDigit1 = guess / 100; int guessDigit2 = guess / 10; int guessDigit3 = guess % 10;   System.out.println("The lottery number is " + lottery);   // Check the guess if (guess == lottery) System.out.println("Exact match: You win \$10,000!");     else if (guessDigit2 == lotteryDigit1 && guessDigit1 == lotteryDigit2) System.out.println("Match all digits: you win \$3,000");     else if (guessDigit1 == lotteryDigit1 || guessDigit1 == lotteryDigit2 || guessDigit1 == lotteryDigit3 || guessDigit2 == lotteryDigit1 || guessDigit2 == lotteryDigit2 || guessDigit2 == lotteryDigit3 || guessDigit3 == lotteryDigit1 || guessDigit3 == lotteryDigit2 || guessDigit3 == lotteryDigit3)   System.out.println("Match one digit: You win \$1,000");     else System.out.println("Sorry, no match. Try again!");       selection = JOptionPane.showConfirmDialog(null, "Would you like to run another?","Confirmation", JOptionPane.YES_NO_OPTION);} while (selection = Yes_Option);             }   }   }   }```
• October 20th, 2010, 08:44 PM
copeg
Re: While JOptionPane equal Yes????
The conditional needs a boolean, so you must use a boolean, or in this case compare the two integers using '=='. In addition, the API for JOptionPane explicitly states what is returned for this method based upon the user action.
Code :

`while (selection == JOptionPane.YES_OPTION);`
• October 20th, 2010, 08:57 PM
maximus20895
Re: While JOptionPane equal Yes????
Ah, that makes sense.

Thanks, I appreciate it!