题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高?
输出结果:299.609375
package game;
public class Ball {
int high;
int n;
double distance=0;
public Ball(int high, int n) {
this.high = high;
this.n = n;
}
public double statLength() {
distance += high;
double once = high;
for (int i = 1; i < n; i++) {
once /= 2;
distance += once * 2;
}
return distance;
}
public static void main(String[] args) {
Ball b = new Ball(100, 10);
System.out.println(b.statLength());
}
}