Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Converting from formulas to java code Math.pow

  1. #1
    Junior Member
    Join Date
    Feb 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Converting from formulas to java code Math.pow

    Hi guy,

    I am new to Java and working on converting these two formulas to Math.pow. I do not think what I did is right. I would really appreciate your comment.

    1- z equal ((x^(2)*5y)^(24))/(\sqrt(y))

    I tried Mat.pow (x,2) * (5*y) *24 / Math.pow (y * 0.5)

    2- z equal ((x^(2)*5y)^(24))/(xy)

    I tried ((Math.pow (x,2) * 5 * y), 24 ) /(x*y)

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    264
    My Mood
    Amused
    Thanks
    8
    Thanked 18 Times in 18 Posts

    Default Re: Converting from formulas to java code Math.pow

    Hi Bandar,

    For the first question:

    It should be Math not Mat.
    Whatever you are, be a good one

  3. #3
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Converting from formulas to java code Math.pow

    In both cases there are two '^' operators in the numerator (top) of the fraction, so I would expect two uses of Math.pow in each numerator. But you only have one.

    Break the expressions up into small pieces and translate one at a time into code. Eg

    x squared ... times 5y ... to the power of 24 ... all divided by the square root of y

    ---

    If you think something is wrong, say what it is: unexpected answer, runtime exception, compiler message, etc.

  4. #4
    Member
    Join Date
    Dec 2013
    Location
    Honolulu
    Posts
    83
    Thanks
    1
    Thanked 4 Times in 2 Posts

    Default Re: Converting from formulas to java code Math.pow

    I see. There is a power twice. x, y. How to write it correctly to come away with the correct answer? How much different answers were there? A lot? Math.pow

  5. #5
    Junior Member
    Join Date
    Feb 2018
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Converting from formulas to java code Math.pow

    I think you might be getting an incorrect ans because of 4/3 in Integer Math give 1 and not 1.33 Try changing you code to what is give below. I tried and worked fine for me.

    radius = diameter / 2.0d;
    volume = (4.0d / 3.0d) * Math.PI * Math.pow(radius, 3);[COLOR="Silver"]

Similar Threads

  1. Question about math.pow and math.sqrt
    By ggx7 in forum Java Theory & Questions
    Replies: 7
    Last Post: March 7th, 2014, 12:51 PM
  2. Question about math.pow
    By felixb in forum Java Theory & Questions
    Replies: 2
    Last Post: October 2nd, 2013, 10:59 AM
  3. [SOLVED] Logic error in Math.pow(a,b) using JOptionPane
    By JAKATAK in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 8th, 2013, 01:18 AM
  4. Math.pow
    By britton33 in forum What's Wrong With My Code?
    Replies: 30
    Last Post: July 1st, 2012, 04:42 PM
  5. Formulas within my code aren't cooperating
    By bohrstein7 in forum What's Wrong With My Code?
    Replies: 15
    Last Post: September 2nd, 2011, 03:30 PM

Tags for this Thread