一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?
代码:
/**
* 反弹距离
* @author cheng
*
*/
public class Ten {
public void bounce(){
double height=
100/
2;
double distance=
100;
for(
int i=
2;i<=
10;i++){
distance+=height*
2;
height=height/
2;
}
System.out.println(
"第10次反弹共经过"+distance+
"米");
System.out.println(
"第10次反弹"+height+
"米");
}
public static void main(String[] args){
Ten ten=
new Ten();
ten.bounce();
}
}
输出结果:
第10次反弹共经过299.609375米
第10次反弹0.09765625米