So i'm just learning java, and i'm writing a simple program, however I have found that it is possible for the users to input something that is not an int, so I looked up online and figured that the best way to resolve this would be to use a try and catch block. However, after I did this the rest of the program gave me an error because I declared a variable in the block. So how do I declare this variable inside the block?
try{
int guessN = guess.nextInt();
}
catch(InputMismatchException err){
System.out.println(err);
}
finally {
int guessN = guess.nextInt();
}
//Location of error
if(guessN < newN){
log("Wrong! The number is more than your guess");
}
Never mind, I just put the code in the try block and it worked XD Sorry!