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

Thread: help with loops... :(

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default help with loops... :(

    im doing a for loop that goes like this.... for (i=1 , i<=30000 , i++)
    ok but want to printout a result every 1000 of the time.... how to do that.. please..


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: help with loops... :(

    Quote Originally Posted by Macgrubber View Post
    im doing a for loop that goes like this.... for (i=1 , i<=30000 , i++)
    ok but want to printout a result every 1000 of the time.... how to do that.. please..
    Simple,

    the % operator will return the remainder that's gotten from the division of two numbers.

    If i%1000 = 0, that means it's divisible by 1000, i.e. i = 0, i = 1000, i = 2000, etc.

    for (i = 1; i < = 30000; i++)
    {
    if (i%1000 ==0)
    print out result
    }

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: help with loops... :(

    See Assignment, Arithmetic, and Unary Operators (The Java™ Tutorials > Learning the Java Language > Language Basics), mainly the remainder operator. Figure out when the remainder of i by 1000 is zero:
     if ( i % 1000 == 0 ){
     
    }

Similar Threads

  1. Nested for loops
    By Fordy252 in forum Loops & Control Statements
    Replies: 2
    Last Post: December 8th, 2012, 11:43 PM
  2. Java Loops help please?
    By Sarah-Perkin in forum Loops & Control Statements
    Replies: 2
    Last Post: December 6th, 2009, 02:52 PM
  3. need help with loops plz
    By Kilowog in forum Loops & Control Statements
    Replies: 4
    Last Post: September 28th, 2009, 08:11 AM
  4. Homework - using 'IF' for 'For Loops'
    By Enzo in forum Loops & Control Statements
    Replies: 5
    Last Post: September 16th, 2009, 10:52 AM
  5. Replies: 11
    Last Post: April 29th, 2009, 03:12 AM