所以我正在做一个项目,将值放入扫描仪对象并检索它们。我第一次输入有问题。要求用户输入ID,然后应该询问姓氏。问题是,当我运行第一个问题时,它会显示它但跳过第一个扫描仪输入并跳转到第二个问题并且输入恢复正常。那么这里发生了什么?我该如何解决这个问题?
//Prompt user for each value
System.out.println("Enter employee Id number:");
String inputId = scanner.nextLine();
System.out.println("Enter employees last name:");
String inputLastName = scanner.nextLine();
System.out.println("Enter employees first name:");
String inputFirstName = scanner.nextLine();
System.out.println("Enter employees salary:");
String inputSalary = scanner.nextLine();
Double inSalary = Double.parseDouble(inputSalary);
答案 0 :(得分:0)
我和你有同样的问题,我用.next()更改.nextLine() 这就是我解决问题的方法
试试这个
System.out.println("Enter employee Id number:");
String inputId = scanner.next();
System.out.println("Enter employees last name:");
String inputLastName = scanner.next();
System.out.println("Enter employees first name:");
String inputFirstName = scanner.next();
System.out.println("Enter employees salary:");
String inputSalary = scanner.next();
Double inSalary = Double.parseDouble(inputSalary);