一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?java代码
时间: 2023-10-20 22:29:12 浏览: 70
以下是Java代码:
```
public class Main {
public static void main(String[] args) {
int n = 10; // 第10次落地
double height = 100.0; // 初始高度
double distance = 0.0; // 总共经过的距离
for (int i = 0; i < n; i++) {
distance += height; // 累加落下的距离
height /= 2; // 计算反弹高度
distance += height; // 累加反弹的距离
}
System.out.println("The total distance traveled after " + n + " bounces is " + distance + " meters.");
System.out.println("The height of the " + n + "th bounce is " + height + " meters.");
}
}
```
输出结果为:
```
The total distance traveled after 10 bounces is 299.609375 meters.
The height of the 10th bounce is 0.09765625 meters.
```
阅读全文