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);
}
}

posted on 2016-11-30 20:33  Heavy_dream  阅读(157)  评论(0编辑  收藏  举报