Hello I'm running this code:
public static int chooseOption() {
int choice = 0;
System.out.println("Enter number [1, 2, 3..]");
do {
try {
choice = sc.nextInt();
} catch ( java.util.InputMismatchException e ) {
System.out.println(e);
break;
}
} while( choice == 0 || choice < 0);
return choice;
}
public static String chooseCom() {
String choice = new String();
int commNumber = 0;
System.out.println("Choose your COM port");
commNumber = chooseOption();
choice = "COM" + commNumber;
System.out.println(choice);
return choice;
}
after that I call - >
Helper.chooseOption();
Helper.chooseCom();
and when I write on the first call 1.1 or just a wrong float(double) value the output is:
Enter number [1, 2, 3..]
1.1
java.util.InputMismatchException
Choose your COM port
Enter number [1, 2, 3..]
java.util.InputMismatchException
COM0
The second java.util.Input.. is the problem why is he poping when I wrote wrong number only on the first call?
sc? Where is it defined, and what's in it?java.util.Scanner