Help with for loops, please!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ryann18
    New Member
    • Oct 2006
    • 22

    Help with for loops, please!!

    Can someone please tell me how to do these???


    Write a for loop to print the odd numbers from 1 to 99 (inclusive).

    Write a for loop to print the multiples of 3 from 300 down to 3.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by ryann18
    Can someone please tell me how to do these???


    Write a for loop to print the odd numbers from 1 to 99 (inclusive).

    Write a for loop to print the multiples of 3 from 300 down to 3.
    You can't just have everything be done for you and expect to become a good programmer. At one point you have to stop and say, "Now let me have a go at this one first before I ask for help".

    Comment

    • LacrosseB0ss
      New Member
      • Oct 2006
      • 112

      #3
      for loops are incredibly simple. However, if you don't know the <b>mod</b> concept, you will have great difficulty with these problems.

      Mod in java is coded with # % # and the result (which can be stored in a variable or output) is the remainder of a division operation.

      Example:
      4/2 = 2 BUT 4%2 = 0
      5/2 = 2.5 BUT 5%2 = 1

      If you use this in the loop, it'll help immensely. However, I'm with r035198x, these are help forums not 'please do my homework' forums. One thing I've learned over the years is that sometimes a programmer's best friend is Google.
      -LB

      Comment

      Working...