Fibonacci Series are number series in which next number is the sum of previous two numbers. For example, if we consider our first two numbers as 0 and 1, then our fibonacci series will look like.
0 1 1 2 3 5 8 13 21 34 55 ....
This can be accomplished in Java with below code.
public class FibonacciSeries { static int num1 = 0; static int num2 = 1; static int nextNum; public static void main(String args[]){ System.out.println(num1); System.out.println(num2); for(int i =0; i < 10; i++){ nextNum = num1+num2; System.out.println(nextNum); num1 = num2; num2 = nextNum; } }
Comments