Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jun 2003
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    finding exponents in java

    how do i find an exponent in java i think its the math.pow() method can someone show me an example of how to call this method correctly.

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts

  • #3
    New Coder
    Join Date
    Jun 2003
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yea i was looking at the pow() method but i dont know how to use it cause i have to take a number as input from the user and raise it to a power so how would i do that? Can i make a variable one of the parameters in the method?

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Yup.

  • #5
    New Coder
    Join Date
    Nov 2004
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Both parameters are variables. Reading the api you'll notice that it returns a double.

    x = Math.pow(y, z);

    You'll get z to the yth power. That is not finding an exponent. What do you mean by finding an exponent?

  • #6
    New Coder
    Join Date
    Jun 2003
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yea sorry what you described is what i want to do. sorry my mind is pretty shot right now cause ive been working on this for hours and i just want to finish it.

  • #7
    New Coder
    Join Date
    Feb 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Math.pow(double y,double z) returns a double value of y raised to the zth power, not the other way around, as turbowrx has said. Since we're being technical.

  • #8
    cfc
    cfc is offline
    Regular Coder
    Join Date
    Dec 2004
    Location
    Keswick, Ontario
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perhaps logarithms could be of some use?

    double exp = Math.log10(double number) / Math.log10(double base);

    Edit: I just realized Math.log is base e, so I switched it to Math.log10
    Last edited by cfc; 02-03-2005 at 03:04 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •