package 递归;
/*
* 汉字定义只是个人为了方便寻找的定义
* 写程序千万不能这么搞 老师说会挨揍
* */
public class 养兔专业户 {
public static void main(String[] args) {
//数组
int[] arr=new int[20];
for (int i = 2; i < arr.length; i++) {
arr[0]=1;
arr[1]=1;
arr[i] = arr[i-2] + arr[i-1];
}
System.out.println(arr[19]);
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++");
//变量
// a---1 1 2 3 5 8
// b---1 2 3 5 8 13
int a=1;int b=1;
for (int i = 0; i < 18; i++) {
int temp=a;
a=b;
b=temp+b;
}
System.out.println(b);
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println(tuzi(20));
}
//上面是一种更好理解递归的思维 可以看看
public static int tuzi(int n){
//思路
//条件出口 n==1 || n==2
//兔子数 1 1
if ( n==1 || n==2) {
return 1;
}else{
return tuzi(n-2)+tuzi(n-1);
}
}
}
//有不懂可以下方评论 晚上放学解答
|
|