【发布时间】:2015-07-05 23:52:49
【问题描述】:
在我的代码(如下)中,input.next(); 只是被跳过了。有人能指出原因吗?
for (int i=0; i<empNum; i++)//for each employee they want to work with
{
System.out.print("\r\n\r\nPROFILE FOR EMPLOYEE #" + (i+1) + ":\r\n"
+"type Hourly(1), Salaried(2), Salaried plus Commission(3)\r\n"
+"Enter 1, 2, or 3 ==> ");//display type gathering
int typeChooser = input.nextInt();//gather type
System.out.print("Name ==> ");//ask for name
String name = input.next();//get name
System.out.print("Social Security Number ==> ");//ask for ssn
String ssn = input.next();//THIS PART IS SKIPPED
System.out.print("Birthday Month (1-12) ==> ");//ask for bdayMonth
int bdayMonth = input.nextInt();//get bdayMonth
System.out.print("Birthday bonus week (1-4) ==> ");//ask for bdayWeek
int bdayWeek = input.nextInt();//get bdayWeek
}
编辑:我只是注意到它被跳过的唯一时间是名称中有空格(即 Bob Smith 而不是 Bob)
【问题讨论】:
-
是否在某个时候遇到异常?
-
我在我的电脑上运行了代码,它工作得很好......“跳过”是什么意思?
-
很多很多行之后,我得到“线程'main'java.util.InputMismatchException中的异常”。我认为这无关紧要,但如果您认为它很快就会到来,也许不是?
-
@Michael 尝试在名字中使用空格来运行它。