[Java04] java big data class
When the precision of basic integers and floating-point numbers does not meet the requirements, you can use the BigInteger and BigDecimal classes provided by java.
Java. math. BigInteger
Java. math. BigInteger provides the following methods:
BigInteger add (BigInteger other) BigInteger subtract (BigInteger other) BigInteger multiply (BigInteger other) BigInteger divide (BigIntegr other) int compareto (BigInteger other) BigInteger mod (BigInteger other)
Static BigInteger valueOf (long x)
The valueOf method can convert a common value to a large value:
BigInteger a=BigInteger.valueOf(100);
Output febonacci Series
Output the first 100 items of the febonacci series, which is about 93 items out of the long range:
public static void fibonacci(){ long[] a=new long[100]; for(int i=0;i<100;i++){ if(i==0){ a[0]=0; System.out.print(a[i]+"\t"); continue; }else if(i==1){ a[1]=1; System.out.print(a[i]+"\t"); continue; } a[i]=a[i-1]+a[i-2]; System.out.print(a[i]+"\t"); if((i+1)%5==0){System.out.println("");} } }
Improvement: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwcmUgY2xhc3M9 "brush: java;"> Public static void maid () {BigInteger [] a = new BigInteger [200]; for (int I = 0; I <200; I ++) {if (I = 0) {a [0] = BigInteger. valueOf (0); System. out. print (a [I] + "\ t"); continue;} else if (I = 1) {a [1] = BigInteger. valueOf (1); System. out. print (a [I] + "\ t"); continue;} a [I] = a [I-1]. add (a [I-2]); System. out. println ("item" + I + ": \ t" + a [I] + "\ t ");}}