import java.util.Scanner; public class Fib2 { public static int F[]; // Saved values public static int fib(int n) { int k; /* ================= Base cases ================= */ F[0] = 1; F[1] = 1; for ( k = 2; k <= n; k++ ) { F[k] = F[k-1] + F[k-2]; // Dyn. prog } return ( F[n] ); } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n, r; F = new int[100]; while ( true ) { System.out.print("n (< 46) = "); n = in.nextInt(); r = fib(n); System.out.println("fib(" + n + ") = " + r); } } }