From 1110ce2bb6c2cfddcb0b1eb0c81f42adde07f70b Mon Sep 17 00:00:00 2001 From: tezivindh Date: Thu, 31 Oct 2024 19:22:13 +0530 Subject: [PATCH] Create FibonacciSeries.java --- Java/FibonacciSeries.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Java/FibonacciSeries.java diff --git a/Java/FibonacciSeries.java b/Java/FibonacciSeries.java new file mode 100644 index 0000000..0a28b78 --- /dev/null +++ b/Java/FibonacciSeries.java @@ -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(); + } +}