package com.demo;

/**
* Created by 莫文龙 on 2018/3/28.
*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;

/**
* 一球从100米高度自由落下,每次落地后反弹回原高度的一半;
* 再落下,求它在第10次落地时,共经过多少米?第十次反弹多高?
*/
public class Demo10 {
//自己写的
public static void main(String[] args) {
BigDecimal tall = new BigDecimal("100");
BigDecimal total = new BigDecimal("100");
//第一次反弹之前的路程为100m,
for (int i = 1; i <= 9 ; i ++) {
total = total.add(tall.divide(new BigDecimal(String.valueOf(Math.pow(2,i)))).multiply(new BigDecimal("2")));
}
System.out.println("在第10次落地时,共经过了" + total + "米");
BigDecimal tenTall = tall.divide(new BigDecimal(String.valueOf(Math.pow(2,10))));
System.out.println("第十次反弹的高度为:" + tenTall);
}
}

//参考答案
class Demo11 {
public static void main(String[] args) {
float heigh = 100,cishu = 10,sum = heigh;
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
for (int i = 1; i < cishu ; i ++) {
heigh = heigh / 2;
sum = sum + heigh * 2;
}
System.out.println("在第10次落地时,共经过了" + sum + "米");
System.out.println("第十次反弹的高度为:" + heigh / 2);
}
}