题解 | #求小球落地5次后所经历的路程和第5次反弹的高度#
求小球落地5次后所经历的路程和第5次反弹的高度
http://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int startHigh = sc.nextInt();
int i = 1;
double startHeight = startHigh;
// 路程
double s = 0;
// 反弹高度
double reHeight = 0;
while(i <= 5){
if(i == 1){
s = startHeight;
}else{
s = s + 2 * startHeight;
}
reHeight = startHeight/2;
startHeight = reHeight;
i++;
}
System.out.println(s);
System.out.println(reHeight);
}
}