[Solved] How to change random number after the user has guessed it right and displays message when user has input a wrong data type


Here’s the logic:

 if(input == randNum){


ReLaunchGame();

}

Now, for method ReLaunchGame() you must either restart the activity, or reset all the textfields.

Just compare their input with the random number you picked. Now, to see if they entered a wrong input. You must first understand exception handling, which I think you do.

enter image description here

(http://www.mathcs.emory.edu/)

Scanner sc=new Scanner(System.in);
try
{
  System.out.println("Please input an integer");
  //nextInt will throw InputMismatchException
  //if the next token does not match the Integer
  //regular expression, or is out of range
  int usrInput=sc.nextInt();
}
catch(InputMismatchException exception)
{
  //Print "This is not an integer"
  //when user put other than integer
  System.out.println("This is not an integer");
}

Thats it. Let me know if it worked! 🙂

solved How to change random number after the user has guessed it right and displays message when user has input a wrong data type