# nested for loop

• November 11th, 2013, 05:00 PM
yuli
nested for loop
Using nested for loops, write a program that will print the numerals 1 through 9 a number of times equal to its square. 1 will print one time (1^2), 2 will print 4 times (2^2), 3 will print 9 times (3^2), etc.

Your output should look like this:

1
2222
333333333
4444444444444444
5555555555555555555555555
666666666666666666666666666666666666
7777777777777777777777777777777777777777777777777
88888888888888888888888888888888888888888888888888 88888888888888
99999999999999999999999999999999999999999999999999 9999999999999999999999999999999

( I don't even know how to start or what the main idea is)
• November 11th, 2013, 05:03 PM
GregBrannon
Re: nested for loop
Here's the main idea: "Using nested for loops." Can you write a for loop? Try writing one or two to get this program going.
• November 11th, 2013, 05:14 PM
yuli
Re: nested for loop
I know how to use for loops but I don't know how to get it to do it the times equal to its square
• November 11th, 2013, 05:21 PM
GregBrannon
Re: nested for loop
Write the for loop. Think about where it starts ( 1, 2, 3, 4, 5, . . . ) - pretty standard - and the upper limit of each starting point. I can't believe you can't get the basic structure of the for loop if you just try.
• November 11th, 2013, 05:28 PM
yuli
Re: nested for loop
I get what you are saying
Code Java:

`for(number =1; number <= 9; number++)`

the thing I don't get is the actual spacing and the numbers
• November 11th, 2013, 05:44 PM
GregBrannon
Re: nested for loop
So one for loop, the outer loop, counts the variable 'number' from 1 through 9. That's useful. What could the inner loop do? Perhaps it could take the 'number,' square it, and print it some number of times. How many times?

Write the inner for loop, then write the rest of the class that goes around the loops and test it.
• November 11th, 2013, 06:52 PM
yuli
Re: nested for loop
ohh ok ill try it like that thank you ..I will see if it works