• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logic with java code

 
Padma Priya
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Could anyone help me out with this logic.

i have a array of characters

char[] = {a b c d e f g h....}

i want to print these characters like this

a c e
b d f

if i add g

then

a d g
b e
c f

if i add h and i then

a d g
b e h
c f i

again when i add j

a e i
b f j
c g
d h

so totally only 3 columns are they
but the rows can increase as new alphabets are added.

Any help really appreciated.

With regards
tirunahari
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your first step should be to define the logic without the Java code. Describe your process in words first -- before writing any code.
 
Greg Charles
Sheriff
Posts: 2987
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Marc, with a small hint that it's easier when printing to the console to write out an entire row, then go on to the next row, than it is to write out a column, then go to the next column. Try to work out how you would do go row by row.
 
Rob Spoor
Sheriff
Pie
Posts: 20555
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need two loops: one for the number of rows, and within that one for the row. First you'll need to calculate how many rows you'll need (hint: Math.ceil can help you with that).
 
Campbell Ritchie
Sheriff
Pie
Posts: 49466
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also be careful about spellings; I think you mean "I" rather than "i" but I can't be sure.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic