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

小球走过路程计算

http://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();
        float sum = h;
        h = h/2;

        //write your code here......
        for(int i=2; i<=n; i++){
            sum = sum + h*2;
            h = h/2;
        }
      
        //输出格式为:System.out.println(String.format("%.3f", h)+" "+String.format("%.3f", sum));
        System.out.println(String.format("%.3f", h)+" "+String.format("%.3f", sum));

    }
}
全部评论

相关推荐

点赞 评论 收藏
分享
牛客83700679...:简历抄别人的,然后再投,有反馈就是简历不行,没反馈就是学历不行,多投多改只要技术不差机会总会有的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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