在蓝桥杯学习中,遇到了很多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;
}