All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hframework.common.util.math.FibonacciUtils Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package com.hframework.common.util.math;

/**
 * Created by zhangquanhong on 2016/12/15.
 */
public class FibonacciUtils {

    public static boolean isMatch(Long number){
        if(number <= 0 ) return false;

        long prevNumber =0, curNumber = 1;
        while(prevNumber + curNumber < number) {
            long tmpNumber = prevNumber + curNumber;
            prevNumber = curNumber;
            curNumber = tmpNumber;
        };
        return prevNumber + curNumber == number ? true : false;
    }

    public static void main(String[] args) {
        System.out.println(isMatch(5L));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy