File size: 563 Bytes
0284885
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package Case4_package;

public class Test {
    public static void main(String[] args) {
        /*
        可爱的小明特别喜欢爬楼梯,他有时候一次爬一个台阶,有时候一次爬两个台阶。
        如果这个楼梯有100个台阶,小明一共有多少种爬法?
         */
        System.out.println(getCount(20));
    }

    public static int getCount(int n) {
        if (n == 1) {
            return 1;
        }
        if (n == 2) {
            return 2;
        }

        return getCount(n - 1) + getCount(n - 2);
    }
}