题目:
题解:
模拟小球下落再回弹的过程,记录做过的路程。
public Map<String, Double> getBallHeight(int initHeight) {
double sum = 0;
double height = initHeight;
int index = 0;
while (true) {
sum += height;
height /= 2.0;
index++;
if (index == 5) {
break;
}
sum += height;
}
Map<String, Double> map = new HashMap<>();
map.put("sum", sum);
map.put("height", height);
return map;
}