# Quick question.

• 12-08-2011, 07:39 PM
juxta
Quick question.
Hi guys, I have a quick question. (Sorry, I'm not very good at for-loops)

In this code:

int value [] = {0};

for (int counter =0; counter < value.length; counter++){
System.out.print(counter + value[counter]);
System.out.print(counter + value[counter]);
System.out.print(counter + value[counter]);
System.out.print(counter + value[counter]);
System.out.print("\n");
}

It prints out 0000. I want it to repeat it again on the next line. Is there an efficient way of doing it?
Thanks.
• 12-08-2011, 07:43 PM
Re: Quick question.
try changing each System.out.print to System.out.println (LN)
That should create a new line each time an output occurs.
• 12-08-2011, 07:44 PM
KevinWorkman
Re: Quick question.
Word to the wise- use more descriptive titles.

What exactly do you want it to repeat on the next line? Another four zeroes? Or each zero on its own line? And what do you mean by efficient?
• 12-08-2011, 07:45 PM
juxta
Re: Quick question.
Quote:

Originally Posted by KevinWorkman
Word to the wise- use more descriptive titles.

What exactly do you want it to repeat on the next line? Another four zeroes? Or each zero on its own line? And what do you mean by efficient?

Yeah, another four zeros. Sorry about that.
• 12-08-2011, 07:45 PM
Re: Quick question.
My example will make a 0 on each line.
• 12-08-2011, 07:46 PM
sunde887
Re: Quick question.
Put a loop inside a loop. The outer loop will produce the inner loop n times. Here is an example

Code:

```for (int i = 0; i < 10; ++i){   for (int i = 0; i < someLength; ++i){     do something   } }```
• 12-08-2011, 07:46 PM
al_Marshy_1981
Re: Quick question.
.........
• 12-08-2011, 07:49 PM
Re: Quick question.
Then make a loop with what you want repeated inside.
• 12-08-2011, 07:50 PM
al_Marshy_1981
Re: Quick question.
I think a ternary if inside a System.out.print might get it down to one line in the for loop.
• 12-08-2011, 07:56 PM
juxta
Re: Quick question.
Quote:

Originally Posted by sunde887
Put a loop inside a loop. The outer loop will produce the inner loop n times. Here is an example

Code:

```for (int i = 0; i < 10; ++i){   for (int i = 0; i < someLength; ++i){     do something   } }```

With the letter 'i', wouldn't that be 'counter' from my code??
• 12-08-2011, 08:01 PM
juxta
Re: Quick question.
Quote:

Originally Posted by juxta
With the letter 'i', wouldn't that be 'counter' from my code??

Ignore that. Thanks sunde :)-:
• 12-09-2011, 04:23 AM
Junky
Re: Quick question.
Quote:

Originally Posted by juxta
int value [] = {0};

Using an array to store a single element is pointless.