斐波拉契
1 public class Fibonacci { 2 3 public static void main(String[] args) { 4 System.out.println(inti(3)); 5 } 6 7 private static long inti(long n) { 8 if (n <= 1) { 9 return n; 10 } 11 long firstLong = 0; 12 long secondLong = 1; 13 for (int i = 0; i < n-1; i++) { 14 long sum = firstLong + secondLong; 15 firstLong = secondLong; 16 secondLong = sum; 17 } 18 return secondLong; 19 } 20 21 }


浙公网安备 33010602011771号