All pastes #797665 Raw Edit

readInput

public java v1 · immutable
#797665 ·published 2007-11-26 04:20 UTC
rendered paste body
public void readInput(){       Scanner scn = new Scanner(System.in);    String stringGuess = JOptionPane.showInputDialog(null, "Guess!");   //    stringGuess = scn.nextLine();        boolean good = false; //flag - tells whether input is an integer or not    int storeGuess = 99;    do    {    	stringGuess = JOptionPane.showInputDialog(null, "Guess!");        try        {            storeGuess = Integer.parseInt(stringGuess);            good = true;        } catch (NumberFormatException e)        {            JOptionPane.showMessageDialog(null, "Not an integer. Please re-enter guess.");        }        if (good && storeGuess <= 0)         {        	JOptionPane.showMessageDialog(null, "Integer must be positive. Reenter integer.");            good = false;        }         if (good && storeGuess > 100)         {        	JOptionPane.showMessageDialog(null, "Integer must be less than or equal to 100. Reenter integer.");            good = false;        }            } while (!good);    int guess = storeGuess; } //input method