|
-
Mar 2nd, 2006, 02:30 PM
#1
Thread Starter
Junior Member
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?
-
Mar 2nd, 2006, 04:34 PM
#2
-
Mar 2nd, 2006, 04:35 PM
#3
Frenzied Member
Re: Why am I getting so many lines?
It looks like the line should print 196 (14x14) times. Does that sound about right?
-
Mar 2nd, 2006, 04:39 PM
#4
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|