import java.util.Scanner; class MyClass { public static void main(String args[]){ Scanner scanner = new Scanner(System.in); int eid,sid; String ename; System.out.println("Enter Employeeid:"); eid=(scanner.nextInt()); System.out.println("Enter EmployeeName:"); ename=(scanner.next()); System.out.println("Enter SupervisiorId:"); sid=(scanner.nextInt()); } }
尝试插入这个时,我得到了输出
Enter Employeeid: 101 Enter EmployeeName: firstname lastname Enter SupervisiorId: Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at com.controller.Menu.<init>(Menu.java:61) at com.tests.Employeetest.main(Employeetest.java:17)
但它的工作在这个
Enter Employeeid: 105 Enter EmployeeName: name Enter SupervisiorId: 501
我想要的是,我必须读取完整的字符串,无论是作为名称还是名字lastname..Eg 原文链接:https://www.f2er.com/java/121738.html