一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高?
package src.stu.day13;
public class ZiYouLuoTi {
// 初始高度,单位为米
static double initialHeight = 100;
// 初始距离,单位为米
static double distance = 100;
// 自由落体次数
static int dropTimes = 10;
public static void main(String[] args) {
// 模拟自由落体过程
for (int i = 1; i < dropTimes; i++) {
distance = distance + initialHeight; // 更新总距离
initialHeight = initialHeight / 2; // 更新高度
}
// 输出总距离和最后的高度
System.out.println("总距离:" + distance + "米");
System.out.println("最后的高度:" + initialHeight / 2 + "米");
}
}