public class HeightDemo {
/**
* 题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;
* 再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?
*/
public static void main(String[] args) {
double h = 100;
double total = 0;
for (int i = 0; i < 10; i++) {
if (i == 0) {
total = total + h;
} else {
h = h / 2;
total = total + 2 * h;
}
}
System.out.println("total=" + total);
System.out.println("h=" + h);
}
}
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240813180353098-2140851696.jpg)