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

Thread: Simple question from a beginner

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

    Default Simple question from a beginner

    int p = 7; 
    if(++p > 10 && p++ > 11) p++;

    I know the output of p after the execution is 8 but I do not know why.
    code would execute as
    (8 > 10 && 8 > 11 ) this is false so the p++ at the end would not be executed. I'm not sure what I'm doing wrong here. I have a quiz this week dealing with these types of problems and this is one of the questions on the practice quiz. The answer is 8 but I would like to know why so that I better understand what I'm doing.

    **Edit**
    Playing around with the code I see that the 8 is coming from within the if statement and not after. I deleted the p++ after the statement and I still get an output of 8. How does this work?

    **Edit**
    Found out where I was messing up.
    The ++p at the beginning of the statement was making the p=8, everything after that was false.
    Last edited by jimmylee7706; March 6th, 2011 at 01:47 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,296
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Simple question from a beginner

    Hi jimmylee, Is your question answered? If so, please use the thread tools link at the top to mark it as solved.

Similar Threads

  1. Quick, beginner-level Java question.
    By DHG in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 27th, 2011, 12:06 PM
  2. beginner and need simple help. please!
    By alal12 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 19th, 2010, 04:38 PM
  3. simple question...
    By chronoz13 in forum Java Theory & Questions
    Replies: 2
    Last Post: February 2nd, 2010, 06:29 AM
  4. Beginner needs help with simple java assignment.
    By joachim89 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 6th, 2010, 06:53 PM
  5. not so simple, simple swing question box
    By wolfgar in forum AWT / Java Swing
    Replies: 2
    Last Post: November 20th, 2009, 02:47 AM