题解 | #求小球落地5次后所经历的路程和第5次反弹的高度#
求小球落地5次后所经历的路程和第5次反弹的高度
http://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int a = in.nextInt();
double d = a;
//记录下落的路程
double sum1 = 0;
//记录弹起的路程
double sum2 = 0;
for(int i = 0; i<5; i++){
sum1 += d;
d = d/2;
sum2 += d;
}
//第五次之后未弹起,须减掉
System.out.println(sum1 + sum2 - d);
System.out.println(d);
}
}
}