[Java] 斐波那契数列 →→→→→进入此内容的聊天室

来自 , 2020-06-12, 写在 Java, 查看 104 次.
URL http://www.code666.cn/view/2cfd4560
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package rili;
  8.  
  9. import java.util.Scanner;
  10.  
  11.  
  12. public class fei {
  13.     public static void main(String[] args) {
  14.         int a[] = new int [50];
  15.         int T,b,c,dis;
  16.         boolean flag = true;
  17.         Scanner sc = new Scanner(System.in);
  18.         T = sc.nextInt();
  19.         while(flag)
  20.         {
  21.           T--;
  22.           if(T<=0)
  23.             flag = false ;
  24.         b=sc.nextInt();
  25.         c=sc.nextInt();
  26.         dis = c-b;
  27.         a[0] = 1;
  28.         a[1] = 1;
  29.         for(int i=0;i<=dis;i++){
  30.             if(i != 0&& i !=1)
  31.                a[i]=a[i-1]+a[i-2];
  32.         }
  33.             System.out.println(a[dis]);
  34.     }
  35.     }
  36. }
  37.  

回复 "斐波那契数列"

这儿你可以回复上面这条便签

captcha