Results 1 to 12 of 12
Thread: Quick question.
- 12-08-2011, 06:39 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 26
- 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.
- 12-08-2011, 06:43 PM #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.
- 12-08-2011, 06:44 PM #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?How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 12-08-2011, 06:45 PM #4
Member
- Join Date
- Nov 2011
- Posts
- 26
- Rep Power
- 0
- 12-08-2011, 06:45 PM #5
Member
- Join Date
- Dec 2011
- Posts
- 9
- Rep Power
- 0
Re: Quick question.
My example will make a 0 on each line.
- 12-08-2011, 06:46 PM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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 } }
- 12-08-2011, 06:46 PM #7
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Re: Quick question.
.........
Last edited by al_Marshy_1981; 12-08-2011 at 06:47 PM. Reason: needs 4 0s
- 12-08-2011, 06:49 PM #8
Member
- Join Date
- Dec 2011
- Posts
- 9
- Rep Power
- 0
Re: Quick question.
Then make a loop with what you want repeated inside.
- 12-08-2011, 06:50 PM #9
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
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, 06:56 PM #10
Member
- Join Date
- Nov 2011
- Posts
- 26
- Rep Power
- 0
- 12-08-2011, 07:01 PM #11
Member
- Join Date
- Nov 2011
- Posts
- 26
- Rep Power
- 0
- 12-09-2011, 03:23 AM #12
Similar Threads
-
Quick question
By Qsc in forum New To JavaReplies: 6Last Post: 07-25-2011, 04:36 AM -
Really Quick question
By Ryan10 in forum New To JavaReplies: 63Last Post: 03-02-2011, 02:11 AM -
Quick Question...
By FatalSylence in forum New To JavaReplies: 4Last Post: 10-15-2010, 02:38 PM -
One last quick question
By jigglywiggly in forum New To JavaReplies: 7Last Post: 01-26-2009, 08:53 AM -
Quick Question
By Graeme in forum New To JavaReplies: 4Last Post: 01-08-2009, 08:01 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks