zoukankan      html  css  js  c++  java
  • 问题:一球从某高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第n次落地时,共经过多少米?第n次反弹多高?

    import java.util.Scanner;
    
    //题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?
    public class BallTest {
        public static void main(String[] args) {
            double firsthight;
            int n;
            Scanner in = new Scanner (System.in);//从键盘读取两个数据
            System.out.println("请输入从多少米落下:");
            firsthight = in.nextDouble();
            System.out.println("请输入第几次落下:");
            n = in.nextInt();
        System.out.println("从"+firsthight+"m"+"第"+n+"次落地经过的距离"+countTotalLong(n,firsthight)+"m");
        System.out.println("从"+firsthight+"m"+"第"+n+"次反弹高度"+countHeight(n,firsthight)+"m");
        }
        public static double countTotalLong(int n,double firsthight){//计算总的路径
            double totalLong =firsthight;
            for(int i = 0;i<n-1;i++){
                totalLong += firsthight/(double)(Math.pow(2,i));
            }
            return totalLong;
        }
        public static double countHeight(int n,double firsthight){ //计算每次反弹高度
            return firsthight/(double)(Math.pow(2,n));
        }
    }
  • 相关阅读:
    08 组件组合使用
    07 React 组件三大属性-----refs
    06 组件三大属性 ----- props
    05 组件三大属性----state
    04 定义组件的两种方式
    03 动态展示列表数据
    02 创建虚拟DOM的两种方式
    C++动多态和静多态
    django1.7+nginx1.4.4的static配置
    redis client API-----------python
  • 原文地址:https://www.cnblogs.com/iamhenanese/p/5466924.html
Copyright © 2011-2022 走看看