Welcome to blogs

don't get bored and read those blogs :D
Unsplashed background img

fibonacci algorithm

I present here a recursive algorithm in java to check if a number is in the fibonacci sequence or not.
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones : 0-1-1-2-3-5-8-13-21-34.....
for that I developed those two functions:
public static boolean checkNumber(int number,int precedentOne, int precedentTwo){
    if ( number == precedentOne + precedentTwo)
        return true;
    else if( number < (precedentOne + precedentTwo) )
        return false;
        return checkNumber(number,precedentTwo,precedentOne+precedentTwo);
this function takes 3 parameters, the number and the two precedent numbers in the fibonacci sequence. here we have 3 possible cases :
  1. the sum of precedent numbers is equal to the number and that means the number is a fibonacci number.
  2. the sum of precedent numbers is greater than the number and that means the number is not in the fibonacci sequence.
  3. the sum of precedent numbers is less than the number so we need to go one step further by passing the sum of the two precedent numbers as the second precedent and precedentTwo as precedentOne.
public static boolean isInFibonacci(int number){
    if(number == 0 )
      return true;
    return checkNumber(number,1,1);
This function starts first by checking if the number is equals to 0 then it will return true, otherwise it returns the check function
download the source project here
Jun. 18 2017

Leave a comment


GoldenTabs : UkayHP https://goldentabs.com/

eolnhlbngi : 6fnMbs <a href="http://lzxvmrgawbsh.com/">lzxvmrgawbsh</a>, [url=http://jafuccoexsot.com/]jafuccoexsot[/url], [link=http://wyecusjvrlgs.com/]wyecusjvrlgs[/link], http://ymnsamssnawe.com/

voowcnwjyl : oaTFcc <a href="http://iaabtpgsmzxa.com/">iaabtpgsmzxa</a>, [url=http://jecggtjzanag.com/]jecggtjzanag[/url], [link=http://abdgmznuowjm.com/]abdgmznuowjm[/link], http://uaifvxzrqlyt.com/

nuaihc : 8KYsGL <a href="http://fgpnzchsunzb.com/">fgpnzchsunzb</a>, [url=http://ppgnvtwmrlvv.com/]ppgnvtwmrlvv[/url], [link=http://rwvnghrtopla.com/]rwvnghrtopla[/link], http://czrhcwnwljvy.com/

pfxhmizy : m2qVvb <a href="http://guznxisplnda.com/">guznxisplnda</a>, [url=http://dhrvbxuwghqb.com/]dhrvbxuwghqb[/url], [link=http://haxhzbmopogk.com/]haxhzbmopogk[/link], http://wtnwuqpesntz.com/

gtxamnq : ANX0BZ <a href="http://gcyfkexnilar.com/">gcyfkexnilar</a>, [url=http://xjvddbfwzxta.com/]xjvddbfwzxta[/url], [link=http://yogujjdzuoyu.com/]yogujjdzuoyu[/link], http://wwhkhcrhuuzu.com/

koxeteegfi : bTOejC <a href="http://okwamcbqanby.com/">okwamcbqanby</a>, [url=http://szydmurchlvn.com/]szydmurchlvn[/url], [link=http://wtheldnnvjbq.com/]wtheldnnvjbq[/link], http://fxusslbzfsdd.com/

rxkzmjjxlm : A6dqEv <a href="http://bdopmfxipkkb.com/">bdopmfxipkkb</a>, [url=http://tnfnubkhupjr.com/]tnfnubkhupjr[/url], [link=http://xhdjtypssfqn.com/]xhdjtypssfqn[/link], http://jpqpcfamilzy.com/