Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Daryn

Thread: Raising a real number

  1. #1
    Naitwa is offline Member
    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Default Raising a real number

    Hey, guys

    Am very new to this programming world, and i choose java, am having a little bit of problem...
    am trying to raise a real number to a negative value e.g
    x-y(x raised to power -y) which can also be written like 1/xk . am trying to run th program each time bt it doesnt give me the desired result. please help....

    here is the code

    public class RaiseRealPower {
    public void run(){
    double value =readInt("Enter value ");
    double power =readInt("Enter power ");
    System.out.println("Answer is " +raiseIntToPower(value,power));
    }

    private double raiseIntToPower(double val,double pow) {

    if (pow>0) return Math.pow(val,pow);
    if (pow<0) return (1)/(Math.pow(val,pow));
    else return 1;

    }
    }

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,600
    Rep Power
    5

    Default Re: Raising a real number

    What result are you getting and what result are you expecting?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    176
    Rep Power
    2

    Default Re: Raising a real number

    When it does 1/x^y wont why still be positive and thus end up with one divided by x raised to the negative y
    Naitwa likes this.
    With the right know how, anything is possible

  4. #4
    Naitwa is offline Member
    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Default Re: Raising a real number

    @jim829, for instance 2^2 gives me 4, and 2^-2 gives me 1..... i was expecting 2^-2=0.25....
    Please assist regards

  5. #5
    Naitwa is offline Member
    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Default Re: Raising a real number

    Quote Originally Posted by Daryn View Post
    When it does 1/x^y wont why still be positive and thus end up with one divided by x raised to the negative y
    yeah! i've gotten the idea! let me try it out!

  6. #6
    Naitwa is offline Member
    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

Similar Threads

  1. Replies: 8
    Last Post: 01-21-2012, 01:14 AM
  2. Dice help. posting the number of times a number is rolled.
    By cookiejarvus in forum New To Java
    Replies: 13
    Last Post: 12-04-2011, 11:08 PM
  3. Raising alerts based on query result across the network
    By srinivasan.sr in forum Networking
    Replies: 2
    Last Post: 07-22-2008, 06:47 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
  •