好,所以我在另一個僵局與我的程序。我需要重複它,但我不明白我正在閱讀的文字中如何去做。它只涵蓋重複的價值,如成績簿計劃。無論如何,我需要程序繼續重複,直到用戶輸入「stop」作爲員工姓名。這是我的代碼到目前爲止:重複程序幫助?
package payroll_program_2; import java.util.Scanner;
public class payroll_program_2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
float hours;
float rate;
String name;
float total_pay;
System.out.println("Please enter employee name");
name = input.nextLine();
if("stop".equals(name))
{ return;
}
System.out.println("Please enter hourly rate");
rate = input.nextFloat();
if (rate <0)
{
System.out.println("Pay rate cannot be negative");
System.out.println("Please enter hourly rate");
rate = input.nextFloat();
}
System.out.println("Please enter hours worked");
hours = input.nextFloat();
if (hours <0)
{
System.out.println("Hours cannot be negative");
System.out.println("Please enter hours worked");
hours = input.nextFloat();
}
System.out.println("Employee's total pay for this week");
total_pay = hours*rate;
System.out.printf("The total pay for %s is $%.2f\n", name, total_pay);
}
}
這就是它。這麼簡單,但我沒有從書中得到它。謝謝你們:) – g3n3rallyl0st 2011-02-13 07:07:14