www.zhnq.net > jAvA BigintEgEr求和

jAvA BigintEgEr求和

BigInteger sum = new BigInteger(); BigInteger temp = new BigInteger(); sum = 0; for(int i=1;i temp = 1; for(int j=1;j temp *= j; } sum += temp; }

这个问题比较简单,如果不要求精度的话,直接double处理就行,如果要求多少精度,用大数处理(BigDecimal)

import java.math.BigInteger; public class SumTest { public static void main(String[] args){ String a = "2222222222222222222222222222222222" ; String b = "4444444444444444444444444444444444" ; String str =new BigInteger(a).add(

import java.math.BigDecimal;public class BigDecimalDemo { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub BigDecimal bg=new BigDecimal("0.4321"); System.out.println(bg.pow(20).toPlainString()); }}

1.BigInteger BigInteger.mod(BigInteger)方法取得正余数2.BigInteger BigInteger.remainder(BigInteger)方法取得余数,符号随原数3.BigInteger[] BigInteger.divideAndRemainder(BigInteger)方法取得整除商[0]和余数[1],余数同2.

BigInteger lotteryOdds = BigInteger.valueOf(1);//相当于 new BigInteger("1"),就是新建一个BigInteger值为1的对象.for (int i = 1; i <= k; i++) lotteryOdds = lotteryOdds.multiply(BigInteger.valueOf(n - i + 1)).divide( BigInteger.valueOf(i));//拆开解

public static void main(String[] args) { int array [] = new int [9]; BigInteger sum =new BigInteger(String.valueOf(0)); for (int i=0;i<9;i++) { array[i] = i+1; sum=sum.add(plus(array[i])); System.out.print(i+1+"的阶乘是:"); System.out.println(plus(array[i]

先转化为string,然后截取小数点前面的数,再转化成bigintegerbigdecimal a = new bigdecimal("23455.789"); string str = a.tostring(); string inte = str.split("\\.")[0]; biginteger b = new biginteger(inte);

valueOf(long类型参数)long类型是有长度限制的999999995000000009999999990000000004999999999已经超出了

public static BigInteger factorial(BigInteger base){ BigInteger flag = new BigInteger("1"); if(base.max(flag).equals(flag)){ return flag; }else{ return base.multiply( factorial(base.subtract(flag))); } }

友情链接:wwgt.net | dfkt.net | lyhk.net | ydzf.net | gyzld.cn | 网站地图

All rights reserved Powered by www.zhnq.net

copyright ©right 2010-2021。
www.zhnq.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com