JAVA program to find fibonacci series for first n terms using method

JAVA program to find fibonacci series for first n terms using method

This JAVA program is to find fibonacci series for first n terms using method.

For example, fibonacci series for first 5 terms will be 0,1,1,2,3.

Dry run of the program has been given here(click on the link) only additional part is the use of function.

As practice you can run the same program with the different ways of using methods.

If you yet need the dry run of the program or any other query, then kindly leave a comment in the comment box or mail me, I would be more than happy to help you.

Program

import java.util.*;

class mr6
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
    		System.out.println("Enter a number to generate fibonacci series for first n terms");
    		int n=sc.nextInt();
    		fibo(n);
    	}
	
	static void fibo(int n)
	{
   		int i,c=0;
   		int a=0;
   		int b=1;
   		System.out.println("Fibonacci series for first "+n+" terms:-");
   		for(i=0;i<n;i++)
   		{
       			System.out.print(c+" ");
       			a=b;
       			b=c;
       			c=a+b;
  		}
	}
}

Output

Share Me!