Skip to content

Commit 6ee6b0b

Browse files
committed
feat: Implement Fibonacci sequence generator to find nth number
📌 Logic: - Takes an integer `n` as input to find the nth number in the Fibonacci sequence. - Initializes first two terms: `a = 0` and `b = 1`. - Iteratively calculates the next Fibonacci numbers using: `b = a + b` and `a = previous b` - Loop continues until the nth term is reached (starting count from 2). - Outputs the nth Fibonacci number. Signed-off-by: Somesh diwan <[email protected]>
1 parent 2a19b47 commit 6ee6b0b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import java.util.Scanner;
22

3-
public class Fibo {
3+
public class FibonacciSequence {
44
public static void main(String[] args) {
55
Scanner in = new Scanner(System.in);
66
int n = in.nextInt();
7+
78
int a = 0;
89
int b = 1;
9-
int count = 2;
1010

11+
int count = 2;
1112
while (count <= n) {
1213
int temp = b;
1314
b = b + a;
1415
a = temp;
1516
count++;
1617
}
17-
1818
System.out.println(b);
1919
}
2020
}

0 commit comments

Comments
 (0)