java if 没有_java – 如何做一个决定没有if语句

我正在学习Java课程,我们还没有正式学习if语句。我在学习,看到这个问题:

Write a method called pay that accepts two parameters: a real number for a TA’s salary, and an integer for the number hours the TA worked this week. The method should return how much money to pay the TA. For example, the call pay(5.50, 6) should return 33.0. The TA should receive “overtime” pay of 1.5 times the normal salary for any hours above 8. For example, the call pay(4.00, 11) should return (4.00 * 8) + (6.00 * 3) or 50.0.

如何不使用if语句解决这个问题?到目前为止,我有这个,但我坚持正常工资:

public static double pay (double salary, int hours) {

double pay = 0;

for (int i = hours; i > 8; i --) {

pay += (salary * 1.5);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值