This paper illustrates the method of recursive Fibonacci sequence in Java mathematical induction. Share to everyone for your reference. Specifically as follows:
The maximum value that an integer can represent is
2147483647
About 2.14 billion, the overflow is not considered here (it overflows when size is 983)!
Import java.util.List;
Import java.util.ArrayList;
/**
* @author Jxqlovejava
* Fibonacci Series/Public
class Fibonacci {public
static list<integer> Fibonacci (int size) throws Exception {
int-i = 0;
int second = 1;
list<integer> result = new arraylist<integer> ();
Result.add (a);
Result.add (second);
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 that are currently being deduced while
(count++ < size) {//fib (0) and FIB (1) Recursively other elements
next = i + second;
i = second;
Second = next;
Result.add (next);
return result;
}
public static void Main (string[] args) throws Exception {
list<integer> Fibarray = Fibonacci (a);
for (int i:fibarray) {
System.out.print (i + "\ t");}}
I hope this article will help you with your Java programming.