Java BigInteger [英] Java BigInteger

查看:60
本文介绍了Java BigInteger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
与BigInteger的差异

Possible Duplicate:
diffucilty with BigInteger

import java.math.BigInteger;  
public class KillerCode{  
    public static void main(String[]args){  
        BigInteger sum=null;  
        for(int i=1;i<=1000;i++){        
            sum=sum+Math.pow(i, i);  
            System.out.println(sum);     
        }    
    }  
} 

当我尝试运行此代码时,出现以下错误消息.

When I try to run this code the following error message is coming up.

对于参数类型BigInteger,double,运算符+未定义.

The operator + is undefined for the argument type(s) BigInteger,double.

我该如何解决? 谢谢.

How can I solve this? Thank you.

推荐答案

您不能将典型的数学运算符与BigIntegers一起使用,请在此处检查

You cannot use the typical math operators with BigIntegers, check here http://docs.oracle.com/javase/6/docs/api/java/math/BigInteger.html

您需要使用BigInteger.add(your numbers here)

进一步的解释

sum = sum.add(new BigInteger(i).pow(i));

这篇关于Java BigInteger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆