[Java] // Fibonacci sequence // f (n) = f (n-1) + f (n-2); // n <= 0 f (n) = 0; f (1) = 1; f (2) = 1; public class Test {public static void main (String [] args) {for (int I = 0; I <10; I ++) {System. out. println ("f (" + I + ") =" + maid (I);} System. out. println ("------------------------"); for (int I = 0; I <10; I ++) {System. out. println ("f (" + I + ") =" + maid (I);} // recursive algorithm static int maid (int n) {if (n <= 0) {return 0;} else if (n = 1) {return 1;} else {return fibonacci1 (n-1) + maid (n-2) ;}// search algorithm static int size = 9999; static double [] fResult = new double [size + 1]; static {// fResult initialize fResult array fResult [0] = 0; fResult [1] = 1; for (int I = 2; I <= size-1; I ++) {fResult [I] = fResult [I-1] + fResult [I-2] ;}} static double fibonacci2 (int n) {return fResult [n];} // generic formula F (n) = (1/√ 5) * {[(1 + √ 5)/2] ^ n-[(1-√ 5) /2] ^ n} [√ 5 indicates root number 5] // grouping policy}