有 n 个台阶,你一次能走 1 个或者 2 个台阶,那么请问,走完这 n 个台阶共有几种方式?
public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入台阶数:"); int num = sc.nextInt(); Integer i = judge(num); if (i==0){ System.out.println("有点正事吧,台阶要大于0"); }else { System.out.println(num+"个台阶共"+i+"种方式能走完"); } } public static Integer judge(int num){ while (num>0){ if (num<=2){ return num; }else{ return judge(num - 1) + judge(num - 2); } } return 0; }