java - Number guessing game -


i have been trying make number guessing game. has set of numbers , supposed count , display number of times have guessed once guess correct number.

currently program runs first 2 steps stops please solve this

import javax.swing.joptionpane;   import java.util.scanner; //scott timmerman twentyquestions  public class twentyquestions {      public static void main(string[] args) {         int number = 500000;         int numberoftries = 0;          joptionpane.showmessagedialog(null, "scott timmerman twentyquestions");         scanner input = new scanner(system.in);         int guess;         boolean win = false;         while (win == false) {              joptionpane.showinputdialog("enter number between 1 , 1,000,000" );             guess = input.nextint();              numberoftries++;              if(guess == number) {                 win = true;             }             else if(guess > number){                 joptionpane.showmessagedialog(null, "your guess " + guess + " greater number");              }             else if (guess < number){                  joptionpane.showmessagedialog(null, "your guess " + guess + " less number");              }         }          joptionpane.showmessagedialog(null, "you lost!\n number " + number );         joptionpane.showmessagedialog(null, "you won!" + numberoftries + " tries");          }   }     `  

it looks though want user enter next guess in dialog box rather @ console. if that's case need use return value joptionpane.showinputdialog. return value text user entered before clicking ok button. need covert integer using integer.parseunsignedint includes handling numberformatexception (in case type in isn't number).

so like:

try {     string guesstext = joptionpane.showinputdialog("enter next guess");     int guess = integer.parseunsignedint(guesstext); } catch (numberformatexception ex) {     ... } 

Comments