Results 1 to 4 of 4

Thread: Why am I getting so many lines?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    19

    Why am I getting so many lines?

    Code:
    public class Loops
    {
    
    	public static void main(String [] args)
    	{
    		for (int count = 1; count<15; count++)
    		{
    			for( int nextCount = 1; nextCount<15; nextCount++)
    			{
    
    			System.out.println("This line will print");
    			}
    		}
    	}
    }
    This nested loop should only execute 14 times for each loop, correct?

    When I run the program, it ouputs "this line will print" what seems like way too many times, why is this?

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Why am I getting so many lines?

    Well it should print it 14x14 times which is almost 200 times (196 to be exact)... How many does it seem like?


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: Why am I getting so many lines?

    It looks like the line should print 196 (14x14) times. Does that sound about right?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    19

    Re: Why am I getting so many lines?

    I gotcha, I was thinking that the loops would add 14+14, not multiply.

    Thanks.

Posting Permissions

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



Click Here to Expand Forum to Full Width