package com.itheima;
public class Test2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// 次数
int count = 200 ;
// 初始高度
float startHigh = 30;
// 获取多少次后的高度
getHigh(count, startHigh);
System.out.println(getHigh(count, startHigh));
}
private static float getHigh(int count, float startHigh) {
// 多少次后的高度
float endHigh = 0;
// 运动的距离,
float S = 0;
// 临时存储
float temp ;
temp = startHigh;
for(int i=0; i < count; i++) {
endHigh = startHigh / 2;
S += startHigh*2;
startHigh = endHigh;
}
System.out.println(" 球所走的距离:"+(S-temp));
return endHigh;
}
}
|