Skip to content

Commit f736005

Browse files
committed
feat: Generate Fibonacci series up to n terms using iterative loop
🧠 Logic: - Read `n` from user input representing number of terms to generate. - Start with base values: a = 0, b = 1. - Print the first two terms (0, 1). - Loop from 0 to n-2 to generate remaining terms: - Compute next term `c = a + b`. - Print `c`, then update `a = b` and `b = c`. Signed-off-by: Somesh diwan <[email protected]>
1 parent ecfef82 commit f736005

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Section8LoopAB/src/FibonacciSeries.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
public class FibonacciSeries {
44
public static void main(String[] args) {
55
Scanner sc=new Scanner(System.in);
6+
67
System.out.println("Program to Fibonacci Series");
78
System.out.println("Enter number to Terms");
89

@@ -12,12 +13,11 @@ public static void main(String[] args) {
1213

1314
System.out.print(a+","+b+",");
1415

15-
for(int i =0; i<n-2;i++)
16-
{
16+
for(int i =0; i<n-2;i++) {
1717
c=a+b;
1818
System.out.print(c+",");
1919
a=b;
2020
b=c;
2121
}
2222
}
23-
}
23+
}

0 commit comments

Comments
 (0)