Results 1 to 4 of 4
  1. #1
    nkg
    nkg is offline Member
    Join Date
    Jan 2014
    Posts
    1
    Rep Power
    0

    Default confusing java expressions with multiple operators

    Can someone please explain the following expressions to me ? I tried running them and those are the answers I got. However, I cannot figure out the working.

    //c = ++a + a++ - --a - a-- + a * + a/a ; //ans is 10

    //c= a* + a/a ; ans. is 1.
    //c= a * +3 ; //ans is 30
    //c =5+ a* +2; //25
    // c= 5+ a* + a/a ; //ans. is 15.

    Thanks.

  2. #2
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    164
    Rep Power
    2

    Default Re: confusing java expressions with multiple operators

    Don't we need to know the initial values of a, b, and c first?

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,526
    Rep Power
    5

    Default Re: confusing java expressions with multiple operators

    I don't see any b's. And c is assigned to. In any event, a is probably initialized to 10 which makes the second answer incorrect.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  4. #4
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    164
    Rep Power
    2

    Default Re: confusing java expressions with multiple operators

    Oh wow. I just assumed that there was a b. I really need to pay more attention :P

Similar Threads

  1. Confusing error during XML transformaiton using Java
    By javax_88 in forum Advanced Java
    Replies: 1
    Last Post: 12-12-2013, 06:06 PM
  2. Replies: 0
    Last Post: 05-02-2012, 11:23 AM
  3. Can I use one switch for multiple expressions?
    By karibo in forum New To Java
    Replies: 2
    Last Post: 11-30-2011, 04:17 PM
  4. Java Operators
    By Ash-infinity in forum New To Java
    Replies: 6
    Last Post: 12-02-2008, 11:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •