[英]Java writing simple program
我正在編寫一個簡單的程序,用戶必須輸入員工的姓名,每小時工資以及他將工作多少小時,並且它將給出員工的姓名以及他的總工資和凈工資這個星期,但我找不到一種將名稱輸入為文字而非數字的方法。
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." );
}
}
}
使用next()
方法讀取String
:
employee = input.next();
這就是需要的(之前Arrem提到的答案)
Scanner in = new Scanner(System.in);
String abc = in.nextLine();
System.out.println("You entered string "+ abc);
使用nextLine()
做到這一點,你應該沒事。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.