打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
OJ 求小球落地5次后所经历的路程和第5次反弹的高度
import java.util.Scanner;
public class Main {
//假设一个球从任意高度自由落下,每次落地后反跳回原高度的一半; 再落下, 求它在第5次落地时,共经历多少米?第5次反弹多高?
//小球反弹高度
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num =sc.nextInt();
sc.close();
int time = 5;
double hihcount = getJourney(num, time);
double hihresult = getTenthHigh(num, time);
System.out.println(hihcount);
System.out.println(hihresult);
}
public static double getTenthHigh(int high,int num){
if(num==1){
return (double)high/2;
}else{
return high/Math.pow(2, num);
}
}
public static double getJourney(int high,int num){
if(num == 1) return high;
double count = high;
        for (int i = 1; i < num; i++) {
count = count + 2* getTenthHigh(high, i);
}
        return count;
    }

}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
判断一个正整数是否为2的n次幂(Java实现)
第四题
求和操作
方法重载
动态控制循环层数
获取GPS模块数据并规格化输出
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服