- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
Fibonacci numbers are the numbers in the following integer sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34...
Shortly, the formula looks F(n)=F(n-1)+F(n-2) => F(0)=0, F(1)=1.
public class Fibonacci {
public static long fibo(int n) {
if (n <= 1) return n;
else return fibo(n-1) + fibo(n-2);
}
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
for (int i = 1; i <= N; i++)
System.out.println(i + ": " + fibo(i));
}
}
Comments
Post a Comment