The example of this article tells the method of Java mathematical induction law not recursively seeking Fibonacci. Share it for everyone for your reference. The specifics are as follows:
The maximum value that Integer can represent is
2147483647
It is about 1.24 billion, and there is no consideration here (it will overflow when the size is 983)!
Import java.util.list; Import Java.util.arrayList;/*** @Author jxqlovejava* Fibonacci {PUBLIC Static list <Integer > Fibonacci (int size) Throws Exception {int FIRST = 0; int Second = 1; list <integer> Result = New ArrayList <Integer> (); Result.add (first); Result.add (sexd); if (size <0) {Throw New Exception ( "Illegal Argument! ");} Else if (size <= 2) {Return Result.sublist (0, size);} Int next; int count = 2; // The number of elements currently derived (count ++ <pt) { / / / / / / Based on fib (0) and fib (1), other elements next = first + sex; first = select; second = Next; Result.add (next);} Public Static Void Main (ST raing [] ARGS ) Throws Exception {list <integer> Fibarray = fibonacci (10); for (int i: fibarray) {system.out.print (i + "/t");}}}It is hoped that this article is helpful to everyone's Java program design.