File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Logic with java code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Logic with java code" Watch "Logic with java code" New topic

Logic with java code

Padma Priya
Ranch Hand

Joined: Feb 01, 2007
Posts: 113
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


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
marc weber

Joined: Aug 31, 2004
Posts: 11343

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.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Greg Charles

Joined: Oct 01, 2001
Posts: 2867

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

Joined: Oct 27, 2005
Posts: 19968

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

How To Ask Questions How To Answer Questions
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 41854
Also be careful about spellings; I think you mean "I" rather than "i" but I can't be sure.
jQuery in Action, 2nd edition
subject: Logic with java code