一球從 100 米高度自由落下,每次落地反彈至原高度一半,再落下。求:
public class BouncingBall {
public static void main(String[] args) {
double height = 100.0; // 初始高度
double totalDistance = 0.0;
for (int i = 1; i <= 10; i++) {
totalDistance += height; // 下落
height /= 2; // 反彈至一半
if (i < 10) totalDistance += height; // 除最後一次不再落下,前 9 次需加上反彈上升距離
}
System.out.println("第 10 次落地總路程:" + totalDistance + " 米");
System.out.println("第 10 次反彈高度:" + height + " 米");
}
}
100 * (1/2)^10 = 100/1024 ≈ 0.09766 米。第 10 次落地總路程:299.609375 米 第 10 次反彈高度:0.09765625 米