Skip to content

Commit

Permalink
Create Fibonacci.java
Browse files Browse the repository at this point in the history
  • Loading branch information
kashish-51 authored Oct 11, 2023
1 parent 6ad3692 commit bea345f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Fibonacci.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.Scanner;

public class Fibonacci {
public static void main(String[] args) {
int term, a = 0, b = 1, c;
System.out.print("Enter the number of terms: ");
Scanner scanner = new Scanner(System.in);
term = scanner.nextInt();

System.out.print("Fibonacci Sequence: ");
for (int i = 1; i <= term; i++) {
System.out.print(a + " ");
c = a + b;
a = b;
b = c;
}
}
}

0 comments on commit bea345f

Please sign in to comment.