未封闭的字符字符文字错误

时间:2014-11-02 07:39:47

标签: java

我的代码如下。不知道如何消除这个问题。我尝试使用next.Line(),但这不起作用。

String demoEmpName;
int demoIdNum;
double demoPayRate;
int demoHoursWorked;

Scanner keyboard = new Scanner(System.in);

System.out.print("What is your name?");
demoEmpName = keyboard.nextString();

System.out.println("What is your ID number?");
demoIdNum = keyboard.nextInt(); 

System.out.println("What is your hourly pay rate?");
demoPayRate = keyboard.nextDouble();

System.out.println("How many hours did you work?");
demoHoursWorked = keyboard.nextInt();

Payroll pyrll = new Payroll(demoEmpName, demoIdNum, demoPayRate, demoHoursWorked);

2 个答案:

答案 0 :(得分:2)

keyboard.nextString()更改为keyboard.next()

Scanner类中没有nextString()方法。

哦,如果您发布的所有这些代码都没有包含在某种方法中,那将是另一个问题。

答案 1 :(得分:0)

Scanner类中不存在nextString()方法。如果员工的姓名只包含一个单词,则应使用: -     demoEmpName = keyboard.next(); 如果名称由多个单词组成,请使用demoEmpName = keyboard.nextLine();