题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半; 再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?
1 public class _010CountBall { 2 public static void main(String[] args) { 3 printDistance(); 4 } 5 6 private static void printDistance() { 7 double h = 100; 8 double sub = 0; 9 for (int i = 1; i < 10; i++) { 10 sub = sub + 2 * h; 11 h = h / 2; 12 } 13 sub = sub - 100; 14 System.out.println("第10次落地时,小球运行的距离为:" + sub); 15 System.out.println("第10次弹起后的高度为:" + h); 16 } 17 }