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

Thread: Question about expression result

  1. #1
    Junior Member
    Join Date
    May 2013
    Location
    Redmond, WA
    Posts
    3
    My Mood
    Cheeky
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Question about expression result

    I have a question about this:

    Which of the following expression results in 45.37:

    This can NOT work, why?

    (int)(45.378) * 100 / 100.0

    BUT this CAN work:

    (int)(45.378 * 100) / 100.0

    Why? THANK YOU!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Question about expression result

    Try working out the expressions by hand.
    Use the parenthesis to control the order that the expressions are evaluated.
    The casting will be done before the arithmetic operator.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2013
    Location
    Redmond, WA
    Posts
    3
    My Mood
    Cheeky
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Question about expression result

    Top work!

    After you mentioned the "casting will be done before the arithmetic operator" it all made sense

    I know increments and decrements like x++ and --x have priority, it did NOT mention in the first 80 pages it was true for "casting".

    THANK YOU so much!!

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Question about expression result

    Hi JohnnyNW and welcome

    Thread moved from member introductions

Similar Threads

  1. I am not getting the result I need
    By Ormolu611 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: April 20th, 2013, 04:44 PM
  2. hi if u can help me please to figure this how D become result of 1
    By ohad in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 4th, 2013, 07:35 AM
  3. advanced regular expression question
    By chopficaro in forum Java Theory & Questions
    Replies: 5
    Last Post: June 8th, 2012, 03:03 PM
  4. newbie question: Error: Could not find or load main class Java Result: 1
    By ideaman in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 1st, 2012, 11:40 PM
  5. [SOLVED] Pattern, regex (regular expression) case sensitivity question
    By chronoz13 in forum Java SE APIs
    Replies: 1
    Last Post: September 7th, 2011, 04:16 AM

Tags for this Thread