Re: How do I get this to output 12 strings per line



Hi,

Something like this will work:

for (int i=0; i<result.length; i++){
System.out.print (result[i]);
if (i%12 == 11){
System.out.println("");
}
}

Note a few important things about this code:

1) You need curly braces around the code inside your FOR loop because
you are doing more than one thing i.e. have more than one statement
ended with a ";". I always use curly braces on my FORs, IFs etc even if
I am only doing one thing. That way I can always put in extra lines
like output lines without having to worry about the braces.

2) "i%12" means get the remainder from dividing i by 12. If i=0, i%12
will be 0. If i=12, i%12 will be 0... but if i=11, i%12 will be 11.
This means execute what is inside the IF every 12th time around..

Rob
:)

.