码迷,mamicode.com
首页 > 编程语言 > 详细

Java小程序之fibonacci数列 BigInteger(高精度整型)

时间:2014-07-07 15:02:14      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:blog   java   for   io   div   new   

package com.java.learning.recursion;

import java.math.*;

public class MainClass {
	public static void main(String args[]){
		for(int i = 0; i < 100; i++){
			f(i+1);
		}
	}
	
	public static BigInteger f(long n){
		if(n <= 2){
			return new BigInteger("1");
		}else{
			BigInteger n1 = new BigInteger("1");
			BigInteger n2 = new BigInteger("1");
			BigInteger temp = new BigInteger("0");
			
			for(long i = 0; i < n -2; i++){
				temp = n1.add(n2);
				n1 = n2;
				n2 = temp;
			}
			System.out.println("第" + n + "项为:" + n2);
			return n2;
		}
	}
}

  

Java小程序之fibonacci数列 BigInteger(高精度整型),布布扣,bubuko.com

Java小程序之fibonacci数列 BigInteger(高精度整型)

标签:blog   java   for   io   div   new   

原文地址:http://www.cnblogs.com/qingbin-bai/p/3815238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!