好,所以我在另一个僵局与我的程序。我需要重复它,但我不明白我正在阅读的文字中如何去做。它只涵盖重复的价值,如成绩簿计划。无论如何,我需要程序继续重复,直到用户输入“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