分析:当n=1时,a(n)=1;当n=2时 ,a(n)=2.

所以当n=>3时,a(n)=a(n-1)+a(n-2)。

 1 public class Test2 {
 2     public static void main(String[] args) {
 3         System.out.println(a(7));
 4     }
 5     
 6     public static int a(int n){
 7         if(n==1){
 8             return 1;
 9         }
10         if(n==2){
11             return 2;
12         }
13         return a(n-1)+a(n-2);
14         
15     }
16 }

 

相关文章:

猜你喜欢
  • 2021-08-23
  • 2021-06-14
  • 2022-12-23
  • 2021-05-31
  • 2021-04-07
  • 2021-10-06
相关资源
相似解决方案