Java中BigInteger类

在蓝桥杯学习中,遇到了很多biginteger的使用


public class B201304 {
    public static void main(String[] args) {
        BigInteger a = BigInteger.ONE;
        BigInteger b = BigInteger.ONE;
        for (int i =3;i<400; i++){
            BigInteger t = b;
            b = a.add(b);
            a = t;
        }
        BigDecimal divide = new BigDecimal(a,110).divide(new BigDecimal(b,110),BigDecimal.ROUND_HALF_DOWN);
        System.out.println(divide.toPlainString().substring(0,103));
    }
    //200:0.61803398874989484820458683436563811772030917980576286213544862270526046281890244969233401224637257135
    //300:0.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748
    //500:0.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748
    //0.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911375

    /*
    import java.math.*;
public class Main {
    public static void main(String args[]){
        BigInteger a = BigInteger.ONE;
        BigInteger b = BigInteger.ONE;
        //转化为斐波那契数列n-1/n的值
        //斐波那契数列的迭代求法
        for(int i=1;i<1000;i++){
            BigInteger t = b;
            b = a.add(b); //大整数的加法
            a = t;
        }
        BigDecimal d = new BigDecimal(a).divide(new BigDecimal(b),100,BigDecimal.ROUND_HALF_UP);//divide(被除数,小数点位数,四舍五入)
        System.out.println(d);
    }

}
     */
}

后学习BigInteger
常量
ZERO,ONE,TEN 返回值为BigInteger类型:有朋友提到的-1,2,源码注释里面已表明不再输出(Not exported.);

	//常量(返回BigInteger类型)
	//有朋友提到的-1和2,源码注释里面已表明不再输出(Not exported.)
	@Test
	public void testFinalNum() {
		//0
		BigInteger zero = BigInteger.ZERO;
		//1
		BigInteger one = BigInteger.ONE;
		//10
		BigInteger ten = BigInteger.TEN;
	}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值