Skip to content

Commit

Permalink
Create FibonacciSeries.java
Browse files Browse the repository at this point in the history
  • Loading branch information
tezivindh authored and x0lg0n committed Nov 1, 2024
1 parent 7818c39 commit 1110ce2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Java/FibonacciSeries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.util.Scanner;

public class FibonacciSeries {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of terms in Fibonacci series: ");
int n = scanner.nextInt();

int first = 0, second = 1;
System.out.print("Fibonacci Series: " + first + ", " + second);

for (int i = 2; i < n; i++) {
int next = first + second;
System.out.print(", " + next);
first = second;
second = next;
}

scanner.close();
}
}

0 comments on commit 1110ce2

Please sign in to comment.