Hi, I am trying to use the pow() method from the math library. I searched this forum for some help and this what I found on how to use it: BigInteger bi = new BigInteger(x); int result = bi.pow(y); I taught when using this constructor x is a string, y has to be an integer. How can I use BigIntegers and integers with the pow() method? What I tried to do is something like this: BigInteger numGrains = new BigInteger("1"); int result = numGrains.pow(numGrains); System.out.print(" " + result + " "); This is the error message I recive when try to compile the class: "pow(int) in java.math.BigInteger cannot be applied to (java.math .BigInteger)int result = numGrains.pow(numGrains)" I understand I'm passing the wrong argument type and when try to pass an integer I get this message: incompatible types found : java.math.BigInteger required: int int result = numGrains.pow(2); ^ Is this not an int? I double checked it in Java API how to pass argument and cannot see the problem. I am confused. Any help would be great! Thanks, moni

How about using the power function in the java.lang.Math package? I think it might be more useful, unless you're already using BigInteger for something else.

Should give you 100.0

If you want to use BigInteger, then watch out for what pow() returns.. another BigInteger, not an int. This should give you 100

[This message has been edited by Mike Curwen (edited September 06, 2001).]

Monika Balogh
Greenhorn

Joined: Aug 28, 2001
Posts: 26

posted

0

Thank your help. I used the BigInteger version and it worked. moni

Don't get me started about those stupid light bulbs.