How to print Fibonacci numbers with Java in 50 iterations
How to print with Java Fibonacci numbers with 50 iterations. The Fibonacci sequence is one of the most famous formulas in mathematics. Each number in the sequence is the sum of the two numbers that precede it. So, the sequence goes: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so on. The mathematical equation describing it is Xn+2 = Xn+1 + Xn. Many sources claim it was first discovered or “invented” by Leonardo Fibonacci. The Italian mathematician, who was born around A.D. 1170, was originally known as Leonardo of Pisa, said Keith Devlin, a mathematician at Stanford University. Only in the 19th century did historians come up with the nickname Fibonacci (roughly meaning, “son of the Bonacci clan”), to distinguish the mathematician from another famous Leonardo of Pisa, Devlin said.
int f1=1,f2=1,acc=0,n=0; while(n<50){ acc=f1+f2; System.out.println(acc); f1=f2; f2=acc; n++; }