/* * System abbrev: * System Name: * Component No: * Component Name: * File Name:FabonacciSequence.java * Author:Peter.Qiu * Date:aug 25, 2014 * Description: <description> */ /* Updation record 1: * Updation Date:aug 25, 2014 * Updator:Peter.Qiu * Trace No: <trace no> * updation No: <updation no> * Updation Content: <list All contents of updation and all methods updated.> */ Package com.qiuzhping.util.interesting; /** * <description functions in a word> * <detail description> * * @author Peter.qiu * @version [version NO, 25, 2014] * @see [related classes/methods] * @since [Product/module version] */ public class Fabonaccisequence { private static fabonaccisequence util = NULL; /** <default constructor> */ Public Fabonaccisequence () { TODO auto-generated Constructor stub } /** <description functions in a word> * 25, 2014 * <detail description> * @author Peter.qiu * @param args [Parameters description] * @return void [return type description] * @exception throws [Exception] [exception description] * @see [Related classes#related methods#related properties] */ public static void Main (string[] args) { Long month = 8; Long Product = 4; Long start = System.currenttimemillis (); System.out.println ("Fabonacci \trabbit:" +getinstance (). Fabonacci (month)); System.out.println ("Take times =" + (System.currenttimemillis ()-start)/1000); System.out.println ("--------------------------------------"); System.out.println ("Fabonacci1 \trabbit:" +getinstance (). FABONACCI1 (month)); System.out.println ("Take times =" + (System.currenttimemillis ()-start)/1000); System.out.println ("--------------------------------------"); System.out.println ("Fabonacci2 \trabbit:" +getinstance (). FABONACCI2 (month,product)); System.out.println ("Take times =" + (System.currenttimemillis ()-start)/1000); for (long i = product; I <= month; i++) { SYSTEM.OUT.PRINTLN ("month =" +i+ "\tfabonacci2 \trabbit:" +getinstance (). FABONACCI2 (i,product)); } } public static Fabonaccisequence getinstance () { if (util = = null) { Util = new Fabonaccisequence (); } return util; } /** <description functions in a word> *pruduct month = 3<br> * 25, 2014 * <detail description> * @author Peter.qiu * @param month:how many months. * @return [Parameters description] * @return Long [return type description] * @exception throws [Exception] [exception description] * @see [Related classes#related methods#related properties] */ Public long Fabonacci (long month) { if (! ( Month < 3)) { for (Long i = 3; I <= month;) { Return Fabonacci (month-1) + Fabonacci (month-2); } } return 1; } /** <description functions in a word> * Pruduct month = 3<br> * 25, 2014 * <detail description> * @author Peter.qiu * @param month:how many months. * @return [Parameters description] * @return Long [return type description] * @exception throws [Exception] [exception description] * @see [Related classes#related methods#related properties] */ Public long fabonacci1 (long month) { Long sum = 1, Lastmonth = 1, lastlastmonth = 1; if (! ( Month < 3)) { for (Long i = 3; I <= month; i++) { Lastlastmonth = Lastmonth; Lastmonth = sum; sum = Lastlastmonth + lastmonth; } } return sum; } /** <description functions in a word> * 25, 2014 * <detail description> * @author Peter.qiu * @param month:how many months. * @param pruductmonth:the production cycle. * @return [Parameters description] * @return Long [return type description] * @exception throws [Exception] [exception description] * @see [Related classes#related methods#related properties] */ Public long Fabonacci2 (long month, long Pruductmonth) { Long sum = 1; if (! ( Month < Pruductmonth)) { for (long i = 0,j = pruductMonth-1; I < month-(pruductMonth-1); i++) { Sum + = Fabonacci2 (Month-j-I, pruductmonth); } } return sum; } } |