File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Logic with java code" Watch "Logic with java code" New topic
Author

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

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
Sheriff

Joined: Oct 01, 2001
Posts: 2834
    
  11

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: 19651
    
  18

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
Also be careful about spellings; I think you mean "I" rather than "i" but I can't be sure.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Logic with java code
 
Similar Threads
The Conditional Operator ?:
Having trouble choosing a data structure
Merging repeted elements in XML
New Mock Exam questions...
conditional operater?