题解 | #求小球落地5次后所经历的路程和第5次反弹的高度#

求小球落地5次后所经历的路程和第5次反弹的高度

http://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int initHigh = sc.nextInt();
        double fiveHigh = initHigh / (Math.pow(2, 5));
        double totalHigh = initHigh;
        for (int i = 1; i < 5; i++) {
            totalHigh += 2 * (initHigh / (Math.pow(2, i)));
        }
        System.out.println(totalHigh);
        System.out.println(fiveHigh);
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务