Results 1 to 4 of 4
  1. #1
    MrPosotive is offline Member
    Join Date
    Sep 2012
    Posts
    68
    Rep Power
    0

    Default Need help with loops

    Hey guys i need help with loops for class. Pretty much i am trying to show some one their hourly pay in increments of 4. im having a tough time making it go up by four, heres my code.

    Java Code:
    public class Hourlypay
    {
    	public static void main(String args[])
    	{
    		
    		
    		
    		
    		for (int p = 4; p <= 40; p++)
    		{
    			System.out.println(p + " ");
    		}
    	}
    }
    its not much but now its going up by one each time i need to make it go up by four.

  2. #2
    Keith Jackson is offline Member
    Join Date
    Sep 2012
    Location
    Maryland, USA
    Posts
    14
    Rep Power
    0

    Default Re: Need help with loops

    Go back and look at this line:

    Java Code:
    for (int p = 4; p <= 40; p++)
    How can you make it increment by 4?

  3. #3
    Amok is offline Member
    Join Date
    Sep 2012
    Location
    Australia
    Posts
    12
    Rep Power
    0

    Default Re: Need help with loops

    Java Code:
    for(int i = 0; i < 40; i = i + 4)

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Need help with loops

    Quote Originally Posted by Amok View Post
    Java Code:
    for(int i = 0; i < 40; i = i + 4)
    Amok, don't spoonfeed. Moreover, that's bad code inasmuch as i = i + 4 is not the syntax commonly used for incrementing a numeric variable.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Help with loops!
    By jrelvi23 in forum New To Java
    Replies: 9
    Last Post: 09-04-2012, 01:36 PM
  2. Replies: 20
    Last Post: 03-22-2011, 04:02 AM
  3. Help with while loops
    By tgwinford in forum New To Java
    Replies: 1
    Last Post: 03-05-2011, 11:03 AM
  4. Help with Loops
    By Spyderpig in forum New To Java
    Replies: 10
    Last Post: 02-17-2011, 08:10 AM
  5. While Loops, need a bit of help.
    By Keno777 in forum New To Java
    Replies: 7
    Last Post: 10-30-2009, 08:24 PM

Posting Permissions

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