Java编写简单程序

时间:2014-04-05 15:44:59

标签: java

大家好我正在编写一个简单的程序,用户必须输入员工的姓名,每小时的工资和工作的小时数,它会给出员工的姓名以及他赚得多少钱本周总薪酬和净工资,但我找不到输入名称作为文本而不是数字的方法。

class payroll
{
    public static void main(String[] args) 
    {
    Scanner input = new Scanner(System.in);
    double count, hours, wage, grosspay, netpay;
    int employee;
    for (;;)
    {
    System.out.print(" Please input the name of the employee followed by the hourly wage followed by the hours worked ");
    employee=input.nextDouble();
    hours = input.nextDouble();
    wage= input.nextDouble();
    grosspay= hours*wage;
    netpay= hours*wage*0.7;
    System.out.print( employee + " gross pay will be " + grosspay + " pounds." + employee + " net pay will be " + netpay + " pounds " + "Please insert name, hours and wage of the next worker." );
    }
    }
}

3 个答案:

答案 0 :(得分:1)

使用next()方法阅读String

employee = input.next();

答案 1 :(得分:1)

这就是所需要的(Arrem之前提到的答案)

Scanner in = new Scanner(System.in);
String abc = in.nextLine(); 
System.out.println("You entered string "+ abc);

答案 2 :(得分:0)

使用nextLine()来做,你应该没问题。