题解 | #小球走过路程计算#

小球走过路程计算

https://www.nowcoder.com/practice/ddbb7021c0a7452f9044564234616913

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        float h=scanner.nextFloat();//初始高度
        int n =scanner.nextInt();//落地次数

        //write your code here......
        

        //输出格式为:System.out.println(String.format("%.3f", h)+" "+String.format("%.3f", sum));
       //h + h/2 +h/2 + h/4 + h/4 ...
       float count = 0;
       float height = 0;
       for(int i = 0 ;i < n ;i++)
       {
            count += h;
            h = h /2;
            if(i == n -1)
            {
                height = h;
            }
            count += h;
       
       System.out.print(String.format("%.3f", height) + " " + String.format("%.3f",count-height ));




    }
}

全部评论

相关推荐

07-25 13:42
门头沟学院 Java
点赞 评论 收藏
分享
人力小鱼姐:实习经历没有什么含金量,咖啡店员迎宾这种就别写了,其他两段包装一下 想找人力相关的话,总结一下个人优势,结合校园经历里有相关性的部分,加一段自我评价
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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