Skip to content

Commit 6f08f89

Browse files
Create Operators and For Loop:Nth Fibonacci Number
1 parent 5ed5b25 commit 6f08f89

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.Scanner;
2+
public class Solution {
3+
public static void main(String[] args) {
4+
Scanner s=new Scanner(System.in);
5+
int N=s.nextInt();
6+
int i;
7+
int new_term=0;
8+
int t1=1;
9+
int t2=1;
10+
11+
if(N==1)
12+
{
13+
new_term=1;
14+
}
15+
else if(N==2)
16+
{
17+
new_term=1;
18+
}
19+
else
20+
{
21+
for(i=3;i<=N;i++)
22+
{
23+
new_term = t1 + t2;
24+
t1 = t2;
25+
t2=new_term;
26+
}
27+
28+
29+
}
30+
31+
System.out.println(new_term);
32+
33+
34+
}
35+
}

0 commit comments

Comments
 (0)