• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing an array X amount of times  RSS feed

 
Gabe Evan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I have an array, let's say:



My output is


Now I'm trying to print that same output X amount of times, X meaning 5 times, 10 times, 20 times, etc.

I tried throwing another for loop over it with an if statement, but I can't get it to work as it needs to.

Any ideas?
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wrapping that loop in an outer loop seems straightforward enough, but what's that about an if-statement? Perhaps you could show us the code you're having the problem with.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That isn't a 2D array because Java® doesn't support 2D arrays. That is an array of arrays, which is better than a 2D array.
Somewhere in Java Puzzlers by Bloch and Gafter, there is a puzzle to find a one‑line instruction to print an entire array of arrays. One of the few I got right first time. You can simply use one method of the Arrays class.
 
Gabe Evan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Wrapping that loop in an outer loop seems straightforward enough, but what's that about an if-statement? Perhaps you could show us the code you're having the problem with.


Yeah, I tinkered with it and got it, I can handle the rest, thanks for the help

 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, that's what I thought you had in mind. Carry on then, we're here if you run into more problems.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!