• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to return items from an array to be printed diagonal  RSS feed

 
Johnny Steele
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I'm working on a method that takes in an array called number and returns its contents to be printed in a diagonal like so:

with tabs in between and each element printed on a new line.
Here is my method which is obviously very wrong but its what I have.

Just cant figure out how to incorporate the new line into a loop or object for that matter.
Thanks,
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use "\n" for newline. Also use StringBuilder instead of + operator to join Strings in a loop.
 
Johnny Steele
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Sorry about posting this twice. i know to use "\n" but as of now I cannot use StringBuilder. I'm just not sure how or where to put "\n" in order to get the desired diagonal printed.
Thanks again for the response,
-john
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
part of your problem is that your inner loop declares "int j", but then you use write "i <" and "i++".

that's going to mess up your outer loop, and your inner loop probably won't do what you want.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually you ought not to use "\n", which is operating-system dependent. You ought to useMore details in System#getProperties().

I think you need some way of counting tabs, and put the \t character before the number in the String. Once yo have managed that, things will get easier. As for StringBuilder, it is easy to use
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!