Hello, I need some help with these simple questions. I am a first year IT college student and I do not know how to apply math.pow to these statements.

Given the following expressions, re-write them as Java expressions using some parentheses to indicate a sequence of operator evaluation.

  1. v = a / b ^ c ^ d – e + f – g * h + i
    Assumptions:
    The ^ symbol in this case means exponentiation.
    Operator application order must follow:
    ^
    /,*
-,+

Operators with the same application order should follow the Leftmost Associativity Rule.

  1. v = 3 * 10 2 / 15 – 2 + 4 ^ 2 ^ 2
    Assumptions:
    The ^ symbol in this case means exponentiation.
    Operator application order must be
    ^
    /,
-,+

Operators with the same application order should follow the Leftmost Associativity Rule.

  1. v = r ^ s * t / u – v + w ^ x – y++
    Assumptions:
    The symbol ^ in this case means exponentiation.
    Operator application order must be
    ++, ^
    /,*
-,+

Operators with the same application order should follow the Leftmost Associativity Rule.

Recommended Answers

All 6 Replies

The Math.pow method simply takes two parameters and raises the first to the power of thesecond, ie
a^b in maths translates to Math.pow(a,b) in Java

but when I express them in letters and not in numbers how do I write that in java?

Sorry, I don't understand that question. The example I gave used letters (?)

Sorry, I mean the sample questions I gave, I was wondering if you could provide some answers for them since similar to those may come out of our exams.

a*b^c+d translates to a*Math.pow(b,c)+d; and you can make the order of evaluation explicit like this (a*Math.pow(b,c))+d; (because Math,pow is a method it always bew called before any other operator that uses its result).
you can work out the rest

Thanks a lot for the information

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.