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.

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.

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.

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.