Results 1 to 9 of 9

Thread: Java looping?

  1. #1
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Java looping?

    I am changing all of my posts bc someone in my class copied and pasted my entire code last time...cheating off of hours of work I put in.
    Last edited by rhym1n; 03-04-2013 at 06:32 AM.

  2. #2
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java looping?

    adfsf
    Last edited by rhym1n; 03-04-2013 at 06:31 AM.

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

    Default Re: Java looping?

    I don't believe you want a loop but an if statement. Your while loop is governed by the following test:

    Java Code:
    annualSales >= salesIncentCalc || annualSales <= salesTarget
    But none of those are updated within the loop so once it enters the loop it will loop forever.

    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java looping?

    Thank you for that. How would I write it so it knows it's between 96,000 (salesIncentCalc) and 120,000 (salesTarget)?

  5. #5
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java looping?

    adfa
    Last edited by rhym1n; 03-04-2013 at 06:31 AM.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,023
    Rep Power
    6

    Default Re: Java looping?

    Well, assuming I understand what you are trying to do you would need three condition tests:

    Java Code:
    if (AnnualSales >= 96000 && AnnualSales <= 120000) { // between the two inclusive
    
    // do something at 25%
    
    } else if (AnnualSales < 96000) {
    
    // do something else at 0%
    
    } else { // at this point AnnualSales must be > 120000 so
    
    // do something here at 31.25%
    
    }
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java looping?

    asdf
    Last edited by rhym1n; 03-04-2013 at 06:31 AM.

  8. #8
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java looping?

    Nevermind, I figured it out thanks to your advice. I seriously couldn't have done it if it wasn't for you. Thank you so much for taking the time to help me.

    Very appreciated :)

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,023
    Rep Power
    6

    Default Re: Java looping?

    That is not advisable. I am not a moderator but it is my experience that it is not permitted to delete your posts. They will probably be restored. It is my opinion that any code posted in this forum becomes public domain and may be used by anyone. After all, this is a forum for learning. When it comes to homework and other related assignments, honor codes prevail.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Help! Using Looping in Java??
    By HappyGirl1184 in forum Eclipse
    Replies: 2
    Last Post: 09-14-2011, 02:40 PM
  2. Java looping (need help)
    By FaintSmile in forum New To Java
    Replies: 6
    Last Post: 07-26-2010, 05:32 AM
  3. basic Java looping
    By ace_hl in forum New To Java
    Replies: 16
    Last Post: 09-03-2009, 02:49 AM
  4. Problem With Looping [JAVA]
    By jude113 in forum New To Java
    Replies: 2
    Last Post: 03-06-2009, 02:00 PM
  5. Java Looping and decision
    By susan in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 05:29 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
  •