Skip to content

Commit f5e8745

Browse files
authored
Fibonacci in Java
1 parent 5ebdf46 commit f5e8745

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Fibonacci Series

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Fibonacci {
2+
static int fib(int n)
3+
{
4+
int f[] = new int[n + 1];
5+
int i;
6+
f[0] = 0;
7+
8+
if (n > 0) {
9+
f[1] = 1;
10+
11+
for (i = 2; i <= n; i++) {
12+
f[i] = f[i - 1] + f[i - 2];
13+
}
14+
}
15+
16+
return f[n];
17+
}
18+
19+
public static void main(String args[])
20+
{
21+
Scanner sc=new Scanner(System.in);
22+
int n = sc.nextInt();
23+
System.out.println(fib(n));
24+
}
25+
}

0 commit comments

Comments
 (0)