1. Member
Join Date
Nov 2011
Posts
30
Rep Power
0

## 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.

2. Member
Join Date
Dec 2011
Posts
9
Rep Power
0

## 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.

3. ## 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?

4. Member
Join Date
Nov 2011
Posts
30
Rep Power
0

## Re: Quick question.

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.

5. Member
Join Date
Dec 2011
Posts
9
Rep Power
0

## Re: Quick question.

My example will make a 0 on each line.

6. ## Re: Quick question.

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

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

7. Senior Member
Join Date
Feb 2010
Location
Waterford, Ireland
Posts
748
Rep Power
7

## Re: Quick question.

.........
Last edited by al_Marshy_1981; 12-08-2011 at 07:47 PM. Reason: needs 4 0s

8. Member
Join Date
Dec 2011
Posts
9
Rep Power
0

## Re: Quick question.

Then make a loop with what you want repeated inside.

9. Senior Member
Join Date
Feb 2010
Location
Waterford, Ireland
Posts
748
Rep Power
7

## Re: Quick question.

I think a ternary if inside a System.out.print might get it down to one line in the for loop.

10. Member
Join Date
Nov 2011
Posts
30
Rep Power
0

## Re: Quick question.

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

Java 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??

11. Member
Join Date
Nov 2011
Posts
30
Rep Power
0

## Re: Quick question.

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

12. ## Re: Quick question.

Originally Posted by juxta
int value [] = {0};
Using an array to store a single element is pointless.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•