小球落地

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

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

import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt()){
            int h = sc.nextInt();
            calc((double)h);
        }
    }
    public static void calc(double h){
        double sum = 0.0;
        sum = h + h + h/2 + h/4 + h/8;
        double bh = (double)h/2;
        for(int i = 0; i <= 4; ++i){
            bh /= 2;
        }
        System.out.println(String.format("%.6f",sum));
        System.out.println(String.format("%.6f",bh * 2));
    }
}
全部评论

相关推荐

点赞 评论 收藏
分享
秋国🐮🐴:拿到你简历编号然后让你知道世间险恶
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务