Site icon NgDeveloper

Java Interesting Problems

How to print Fibonacci Series Till 1000 ?

import java.math.BigInteger; 

public class FibonacciSeries
{
	public static void main(String[] args) {
	    int input = 100;
		BigInteger n1=BigInteger.valueOf(0),n2=BigInteger.valueOf(1),n3=BigInteger.valueOf(0);
		for(int i=2;i<=input;i++) {
			n3=n3.add(n1).add(n2);
			System.out.println(n3);
			n1=n2;
			n2=n3;
		}
	}
}

Learning from the above program:

Exit mobile version