├── FibonacciSequenceGenerator.java └── README.md /FibonacciSequenceGenerator.java: -------------------------------------------------------------------------------- 1 | public class Fibonacci { 2 | public static void main(String[] args) { 3 | int numTerms = 10; // Change this value to generate a different number of terms 4 | System.out.println("Fibonacci Sequence of " + numTerms + " terms:"); 5 | printFibonacci(numTerms); 6 | } 7 | 8 | public static void printFibonacci(int numTerms) { 9 | int num1 = 0, num2 = 1; 10 | for (int i = 0; i < numTerms; i++) { 11 | System.out.print(num1 + " "); 12 | int sum = num1 + num2; 13 | num1 = num2; 14 | num2 = sum; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fibonacci Sequence Generator 🌀 2 | 3 | This Java program generates the Fibonacci sequence up to a specified number of terms. 4 | 5 | ## Introduction ℹ️ 6 | 7 | The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. This program calculates and prints the Fibonacci sequence up to a specified number of terms. 8 | 9 | ## Features ✨ 10 | 11 | - **Customizable Number of Terms**: Change the value of `numTerms` to generate a different number of terms in the Fibonacci sequence. 12 | - **Simple Interface**: Easy-to-understand Java program with clear instructions. 13 | 14 | ## Usage 🖥️ 15 | 16 | 1. Clone or download the repository. 17 | 2. Compile the `FibonacciSequenceGenerator.java` file. 18 | 3. Run the compiled Java program. 19 | 4. Follow the instructions to specify the number of terms for the Fibonacci sequence. 20 | 5. The program will generate and display the Fibonacci sequence up to the specified number of terms. 21 | 22 | ## Example 23 | 24 | ```bash 25 | $ javac Fibonacci.java 26 | $ java Fibonacci 27 | Enter the number of terms: 10 28 | Fibonacci Sequence of 10 terms: 29 | 0 1 1 2 3 5 8 13 21 34 30 | --------------------------------------------------------------------------------