+ 2
Comparar valor vacío de scanner de tipo int
Compare a void value from scanner (type int) https://code.sololearn.com/crCRg2BNHMS2/#java
2 Réponses
+ 2
nextInt only returns integers. If there isn't an integer available, it raises an exception. You have two choices: deal with the exception or test to see if an integer is available. This is your test:
if(!sc.hasNextInt()){
vacio();
}
else {
i = sc.nextInt();
System.out.print("Gracias"); //Thanks
}
+ 2
Note: allocating a second scanner as your code attempts won't work. All of the input goes to the first one.