# Nested loops

• April 29th, 2014, 07:53 PM
Rookie
Nested loops
I need to use a nested loop to print the following output but an unsure how to do it with the two zeros printing after the 9. Any help appreciated. Need to print:
1122334455667788990011223344556677889900

Thanks. This is a method that I wrote, but I had to print the zeros as literals in a separate print statement. I know that there must be a better algorithm.

Code Java:

```public static void drawNumbers(){ for (int line = 1; line <= 2; line++){ for (int i =1; i <= 9; i++){ for (int j =1; j<=2; j++){ System.out.print(i); } } System.out.print("00"); } }```
• April 29th, 2014, 08:23 PM
GregBrannon
Re: Nested loops
Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

Show what you've tried or can do with/without the zeros.
• May 2nd, 2014, 05:25 PM
Rookie
Re: Nested loops
I posted my code above. Any help on improving appreciated.
• May 2nd, 2014, 05:35 PM
Norm
Re: Nested loops
I don't see any comments in the code that describes the steps the code is trying to take to solve the problem.
Can you add some comments saying what the different parts of the code are trying to do?
• May 2nd, 2014, 06:43 PM
GregBrannon
Re: Nested loops
Have you heard of the remainder or modulus operator? I think that combined with one loop will accomplish the task.
• May 12th, 2014, 06:38 PM
biter
Re: Nested loops
for 1 to 10
....
print i%10
• May 14th, 2014, 03:55 PM
rita khatei
Re: Nested loops
Code :

`** code removed`
are u satisfy with this???
• May 14th, 2014, 05:11 PM
copeg
Re: Nested loops
@ rita khatei, please don't do the OP's work for them. Rather, push them in the right direction. Your code has been removed based upon forum policy - edit it again and further action will be taken.