Fibonacci series || series || Java program || Java
In this, we are going to write a  program to print the 1, 1, 2, 3, 5, 8, … up to n in series in Java.


import java.util.*;

class Series10 
{
    public static void main(String[] args) 
    {
        int i, n, f = 1, s = 0, t;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number of terms:");
        n = sc.nextInt();
        for (i = 1; i <= n; i++) 
        {
            t = f + s;
            System.out.print(t + " ");
            f = s;
            s = t;
        }
    }
}

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post