Fibonacci series starts with 0

Program:-

package payilagam.institution;

public class Fiboswap {

	public static void main(String[] args)
	{
      int first = -1;
      int second = 1;
      while(first+second<=10)
      {
    	  System.out.println(first+second); //0 1 1 2 3 5 8 
    	  second = second + first; //1+ -1 =0 0=0+1=1
    	  first = second - first;  //0-(-1)=1 1=1-1=0
    	
    	  
      }
       
	    
	}

}

Output Screenshot:-

Leave a Reply

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