Results 1 to 6 of 6

Thread: Iterative help

  1. #1
    Jnoobs is offline Member
    Join Date
    Oct 2009
    Posts
    13
    Rep Power
    0

    Default Iterative help

    Im writing a program that takes a number inputed and prints the first n positive numbers beginning at 0 by 10's, separated by spaces.

    For example: n=4 prints 0, n=65 prints 0 10 20 30 40 50 60

    Im not understanding how to write this using an iterative method. Any help please?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    Write out a description of what it is you would need to do to do this by hand, step by step...then use that to structure your code.

  3. #3
    Jnoobs is offline Member
    Join Date
    Oct 2009
    Posts
    13
    Rep Power
    0

    Default

    i have tried that but i cant seem to understand what i would need to write in order for it to print out 10 20 30 40 50 60 if n=65

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    You'll need a loop, probably.

    Now think what the exit condition will be for that loop.

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,993
    Rep Power
    9

    Default

    This is a fundamental skill for programmers. You know how to do it by hand, obviously, because you can describe what you need to do. Do it by hand, and stop to think before you write each number: how did I figure that out? How would I tell somebody else, who had no other knowledge, how to do that?

  6. #6
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    5

    Default

    Assuming you know how to write an iterative statement, they don't have to just increment by one (e.g. n++, ++n) but can be incremented by any amount (e.g. n+=2, n+=3, n+=4 , increments n by 2, 3, 4 respectively).

    I can't give away too much too soon but I hope this helps.
    If you're still struggling then post back.

Similar Threads

  1. Help needed to turn a recursive method into iterative
    By mercyfulfate in forum New To Java
    Replies: 5
    Last Post: 07-16-2010, 06:13 PM
  2. Turning Recursion Method into Iterative method
    By mattakuevan in forum New To Java
    Replies: 9
    Last Post: 06-15-2010, 06:46 AM
  3. Replies: 3
    Last Post: 02-09-2010, 05:22 AM
  4. Iterative Algorithms
    By Zosden in forum Algorithms
    Replies: 1
    Last Post: 07-05-2008, 06: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
  •