aspose file tools*
The moose likes Beginning Java and the fly likes pow() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "pow()" Watch "pow()" New topic
Author

pow()

Monika Balogh
Greenhorn

Joined: Aug 28, 2001
Posts: 26
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

Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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
Thank your help.
I used the BigInteger version and it worked.
moni
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: pow()