验证中...
Languages: Java
Categories: 算法分析
Latest update 2019-11-08 20:05
digui.java
Raw Copy
package mystudy;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
System.out.println(febonacci(12));
System.out.println(stepNum(40));
}
/**
* 递归实现斐波那契数列
*/
public static int febonacci(int n) {
if(n==1|| n==2) {
return 1;
} else {
return febonacci(n-1) + febonacci(n-2);
}
}
/**
* 递归实现走阶梯问题
*/
public static int stepNum(int n) {
if(n==1) { return 1; }
else if(n==2) { return 2; }
return stepNum(n-1) + stepNum(n-2);
}
/**
* 电影院问多少排问题
*/
public static int sortNum(int n) {
if(n==1) {
return 1;
}else {
return sortNum(n-1)+1;
}
}
}

Comment list( 0 )

Sign in for post a comment

Help Search