| Author |
Logic with java code
|
Padma Priya
Ranch Hand
Joined: Feb 01, 2007
Posts: 112
|
|
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
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
sscce.org
|
 |
Greg Charles
Bartender
Joined: Oct 01, 2001
Posts: 2535
|
|
|
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
Joined: Oct 27, 2005
Posts: 19214
|
|
|
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).
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
|
Also be careful about spellings; I think you mean "I" rather than "i" but I can't be sure.
|
 |
 |
|
|
subject: Logic with java code
|
|
|