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

题目描述

假设一个球从任意高度自由落下,每次落地后反跳回原高度的一半; 再落下, 求它在第5次落地时,共经历多少米?第5次反弹多高? 

/**
 * 统计出第5次落地时,共通过多少米?
 * 
 * @param high 球的起始高度
 * @return 英文字母的个数
 */
public static double getJourney(int high) {
    return 0;
}

/**
 * 统计出第5次反弹多高?
 * 
 * @param high 球的起始高度
 * @return 空格的个数
 */
public static double getTenthHigh(int high) {
    return 0;
}

输入描述

输入起始高度,int型

输出描述

分别输出第5次落地时,共通过多少米第5次反弹多高

输入例子

1

输出例子

2.875
0.03125

算法实现

import java.util.Scanner;

/**
 * All Rights Reserved !!!
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
//        Scanner scanner = new Scanner(Main.class.getClassLoader().getResourceAsStream("data.txt"));
        while (scanner.hasNext()) {
            double h = scanner.nextDouble();
            System.out.printf("%g\n", getJourney(h));
            System.out.printf("%g\n", getTenthHigh(h));
        }

        scanner.close();
    }

    private static double getTenthHigh(double h) {
        return h / 32;
    }

    private static double getJourney(double h) {

        double up = (Math.pow(0.5, 4) - 1) / (0.5 - 1);
        double down = (Math.pow(0.5, 5) - 1) / (0.5 - 1);

        return h * 0.5 * up + h * down;
    }
}
相关文章
相关标签/搜索