Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java BigInteger [duplicate]

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.

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

How can I solve this? Thank you.

like image 791
KillerCode Avatar asked Aug 01 '26 21:08

KillerCode


1 Answers

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

you need to use BigInteger.add(your numbers here)

Further Explination,

sum = sum.add(new BigInteger(i).pow(i));
like image 120
Austin Avatar answered Aug 08 '26 09:08

Austin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!