新价格
政府刚刚对您的商品征收了新税。您想一次性更新库存中的所有价格,为每个价格增加其数值的一半。
本练习是课程的一部分
Java 中级
练习说明
- 为您的函数提供正确的类型。
- 返回参数的 1.5 倍。
- 使用合适类型的
for循环。
交互式实操练习
通过完成这段示例代码来试试这个练习。
class PriceCalculator {
// Give the correct type to your function
static ____ oneAndAHalf(double a) {
// Use the proper operations to get the result
return ____;
}
public static void main(String[] args) {
double[] numbers = {76, 38.3, 10, 42, 98.5, 84, 50, 72.2, 98, 96};
// Use the congruous type of for loop
for (____) {
numbers[i] = oneAndAHalf(numbers[i]);
System.out.println(numbers[i]);
}
}
}