您好,我正在运行此代码:
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;
}
之后我打电话 - >
Helper.chooseOption();
Helper.chooseCom();
当我在第一次调用 1.1 或只是一个错误的 float(double) 值时写入输出是:
Enter number [1, 2, 3..]
1.1
java.util.InputMismatchException
Choose your COM port
Enter number [1, 2, 3..]
java.util.InputMismatchException
COM0
第二个 java.util.Input.. 问题是为什么当我只在第一次通话时写错号码时他会弹出?