Results 1 to 6 of 6
  1. #1
    xp_vista007 is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Default How to solve this :

    Can anyone help me solving this :

    For int a = 2 , and double b = 2.0, what are the results of the following expressions :
    a = 12 * 10 % 5 * (22 * 3 % 2);
    b += 1.5 * 3 + (a++);
    a %= 3/a + 3 * (++b).


    For x = 1 and z = 0 , what are the results of the boolean expressions :
    (true) && (x >= x) || !((x > 0) && (x > y))
    ((x != 1) == !(x == 1)) ^ (z++ && x)

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Why can't you do this? We know how to do this already and we don't do peoples homework, we will, however; help you if you get stuck.

  3. #3
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    103
    Rep Power
    0

    Default

    Yes. Review order of precedence and post/pre-increment. Also know that a statement like a += 1 is a shortcut for a = a + 1. If I were you, I would work these out on paper rather than type them into a program. It's important to understand these rules.

  4. #4
    xp_vista007 is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Default

    I can do this, but i have problems with statements like this ("+=", "%="),
    i know that b++ is like b = b + 1; but what with ++b ????

  5. #5
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    103
    Rep Power
    0

    Default

    b++ is an example of postincrement. ++b is an example of preincrement. By themselves, there is no difference they just increment b:

    int b = 0;
    b++; //add 1 to b (b is 1)
    ++b; //add 1 to b (b is 2)

    But the difference can be seen in this example:
    Java Code:
    int b;
    b = 0;
    System.out.println(b++);  //will print 0
        	 
    b = 0;
    System.out.println(++b); //will print 1
    In the first output statement above, 0 will be printed because b is incremented after the println() method is executed (postincrement). In the second output statement, 1 will be printed because b is incremented before the println() method is executed (preincrement). You can think of postincrement and preincrement as shortcuts. You can write equivalent code by incrementing b outside of the println() method.

    b += 1 is equivalent to b = b + 1
    b %= 1 is equivalent to b = b % 1
    b -=1 is equivalent to b = b - 1
    b *= 1 is equiavlent to b = b * 1;
    See the convention?

  6. #6
    xp_vista007 is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

Similar Threads

  1. Please help me to solve it(jsp)
    By srengvichet in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-15-2010, 04:52 PM
  2. Please help me solve them
    By quangtrung89 in forum New To Java
    Replies: 2
    Last Post: 11-26-2009, 11:08 PM
  3. PLS PLS PLS PLS solve this
    By unagie in forum New To Java
    Replies: 10
    Last Post: 07-11-2009, 10:10 PM
  4. Plz solve this....
    By theone3nu in forum New To Java
    Replies: 9
    Last Post: 12-23-2008, 10:42 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
  •