- public class Test {
-
- public static void main(String[] args) {
-
- Test t = new Test();
- for(int i = 1; i <= 10; i++){
- P.rintln(t.getHeight(i, 100));
- P.rintln(t.getJourney(i, 100));
- }
-
- }
-
- public double getJourney(int n, double temp){ //获取走过的路程
-
- if(n == 1){
- return 1.5 * temp;
- }
- return getJourney(n - 1, temp / 2) + temp * 1.5;
- }
-
- public double getHeight(int n, double height){ //获取高度
-
- if(n == 1){
- return height / 2;
- }
- height = height / 2;
- return getHeight(n - 1, height);
- }
- }
复制代码
2了,递归还是不熟- -,花了这么久时间 |