Fibonacci

Fibonacci Sequence = 0, 1, 1, 2, 3, 5, 8, 13, 21, …. “3” is obtained by adding the third and fourth term (1+2) and so on. For example, the next term after 21 can be found by adding 13 and 21. Therefore, the next term in the sequence is 34.

Program:-

package forloop;

public class Fibonacci {
       
	
	 
	public static void main(String[] args)
	{    
		int first = 0;
	    int second = 1;
       for(int i =1; i<=10;i++)
       {   int Fibo= first+second;
    	   System.out.println(Fibo);
    	   first = second;
    	   second= Fibo;
       }
	}

}

Output Screenshot:-

Leave a Reply

Create your own website, free on WordPress.com.Create your own website.
Start free