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

1. ## about Operator Precedence

[need help]

i have a question and task about operator precedence

1.what is the operator precedence
2.how to use operator precedence for this :

>> 3*10*2/15-2+4^2^2 ?
>> a/b^c^d-e+f-g*h+i ?
>> r^s*t/u-v+w^x-y++ ?

2. ## Re: about Operator Precedence

If you search for "java operator precedence", you'll find this page:
Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)

'operator precedence' is the rule that programming languages use to decide which operators to apply first. For example 2 + 3 * 4 equals 14 (2 + (3 * 4)), not 10 ((2 * 3) + 4).

3. ## Re: about Operator Precedence

To prevent confusion and mistakes, ALWAYS use ()s to isolate all the operations.

4. ## Re: about Operator Precedence

Originally Posted by Sean4u
14 (2 + (3 * 4)), not 10 ((2 * 3) + 4).
Considering that they are 2 different equations I'm not surprised they give different results.

5. ## Re: about Operator Precedence

So that's why I typed the wrong (right) result the first time... :facepalm:

7. ## Re: about Operator Precedence

If you are good in mathematics, you can apply similar rules here.