fibonacci series

Easy Java 🔄 Loops
👁️ 8 views 👤 By Super Admin 📅 Feb 03, 2026

❓ Question

Write a java program generate fibonacci series.

✅ Solution

class Fibo
{
    public static void main(String[] args) {
        int n = 10; // Change this value to compute more or fewer Fibonacci numbers
        int a = 0, b = 1;
        System.out.print("Fibonacci Series up to " + n + " terms: ");
        for (int i = 1; i <= n; i++) {
            System.out.print(a + " ");
            int next = a + b;
            a = b;
            b = next;
        }
    }
}

💻 Submit Your Solution

Please login to submit your solution and earn points.

Login Now