+ 2
Fibonacci numbers in Java
Hey guys! I've started learning Java a week ago and met a problem, that I can't solve by myself. So I need your help. Thing is, I understand, how to make loop to get like "n" mount of Fibonacci numbers, but I can't make program to start counting from (for example) 12-d or 13-th number. https://code.sololearn.com/cavzhCCmXKvf/#java - here Is code I made. As you can see, It knows "first" two nubmers and starts counting from them. I want It to count like 20 numbers, than get 15-th and start counting 20 nu
4 Réponses
+ 1
If you want to start from the 13th number, your program has to calculate the numbers til the 12d anyway. Then you use a loop to loop n-times, but you start with your number 11 and 12.
Or
if you want to start from the 13th number, your program calculates the sum of the number n and the number you want to start with (13). Then it does a loop which loops as long as the sum is greater. In the loop is an if statement wich decides depending on the variable which is incremented if the fibonacci number should be printed(incremented variable >= 13)
+ 1
One more tip, if you want to use very large Integers, there's a BigInteger class which fits into this great.
Here's my "normal" fibonacci series code:
https://code.sololearn.com/cM8HVyQmi6ut/?ref=app
+ 1
Thank you for your advices! I had no time to practice and today suddenly got an idia! Check this one out - https://code.sololearn.com/cGGF602M009y/#java Finally! I did what I wanted to do! I will learn more about text entry and improve this code. Thank you a lot, again.
0
Thank you very much! I will try it