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 7 of 7

Thread: about Operator Precedence

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile 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++ ?

    so please help me i'm new in java program


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default 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).
    Last edited by Sean4u; August 7th, 2011 at 05:29 AM. Reason: can't count

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,186
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: about Operator Precedence

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

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,514
    My Mood
    Grumpy
    Thanks
    0
    Thanked 165 Times in 156 Posts

    Default Re: about Operator Precedence

    Quote Originally Posted by Sean4u View Post
    14 (2 + (3 * 4)), not 10 ((2 * 3) + 4).
    Considering that they are 2 different equations I'm not surprised they give different results.
    Improving the world one idiot at a time!

  5. #5
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: about Operator Precedence

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

  6. #6
    Member
    Join Date
    Mar 2011
    Posts
    32
    My Mood
    Worried
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: about Operator Precedence

    Last edited by diyaots; November 21st, 2011 at 03:48 AM.

  7. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: about Operator Precedence

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

Similar Threads

  1. Operator % cannot be applied to java.lang.String,int?
    By javarum in forum Java Theory & Questions
    Replies: 8
    Last Post: July 12th, 2011, 08:06 PM
  2. Sobel Operator (Edge Detection)
    By Kimimaru in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 18th, 2011, 05:21 PM
  3. how to extract variables,keywords,operator...
    By Nanda in forum Java Theory & Questions
    Replies: 1
    Last Post: November 12th, 2009, 09:19 PM
  4. Operator Problem
    By KevinGreen in forum Algorithms & Recursion
    Replies: 2
    Last Post: November 2nd, 2009, 08:50 AM
  5. he operator / is undefined for the argument type(s) String, int
    By mtbr00x in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: September 8th, 2009, 08:34 PM