• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

pow()

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank your help.
I used the BigInteger version and it worked.
moni
 
This looks like a job for .... legal tender! It says so right in this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic