【发布时间】:2013-11-19 01:02:10
【问题描述】:
public class ComputePay
{
/**
Compute pay (including overtime) for worker. Hours in excess of 40 hours
are paid at time-and-a-half.
@param wage the hourly wage for the employee
@param hoursWorked the number of hours worked by employee in one week
@return the amount of pay employee earned
*/
public static double payForWeek(double wage, double hoursWorked)
{
double totalPay = 0.0;
if (hoursWorked <= 40);
{
totalPay = hoursWorked*wage;
}
else if(hoursWorked > 40);
{
totalPay = (40*wage+(wage*(hoursWorked-40)));
}
return totalPay;
}
}
它给了我一个没有 if 错误的 else。不知道我在这里做错了什么
【问题讨论】:
-
问题在于 if 和 else if 语句末尾的分号。删除它们
-
在您阅读问题之前,您可以知道答案。我们应该有一个检测这些常见错误的机器人..
-
去掉 if 条件后的分号。此外,您的 else 子句不需要是 else-if,因为如果工作时间不 40
-
我很想知道对于初学者来说,是否还有比这更多的基本错误
标签: java loops if-statement