- package com.cai.test;
- public class FFBody {
-
- public static void main(String[] args){
- freeFallingBody(0F,100F,1);
- }
-
- /**
- *
- * @param distance 小球经过距离
- * @param initHigh 小球反弹高度
- * @param times 小球第times次落下
- */
- public static void freeFallingBody(double distance,double initHigh,int times){
- if(times<10){
- distance += initHigh*1.5;
- initHigh *= 0.5;
- times++;
- //递归
- freeFallingBody(distance,initHigh,times);
-
- }else if(times==10){
- distance += initHigh*1.5;
- initHigh *= 0.5;
-
- System.out.println("小球第"+times+"次时经过"+distance+"米");
- System.out.println("小球第"+times+"次时反弹"+initHigh+"米");
- }
- }
- }
复制代码 |