Re: How do I get this to output 12 strings per line
- From: "Robert Mark Bram" <robertmarkbram@xxxxxxxxx>
- Date: 30 Oct 2006 13:46:21 -0800
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
:)
.
- References:
- How do I get this to output 12 strings per line
- From: Louie LaRue
- How do I get this to output 12 strings per line
- Prev by Date: a problem in transfer a int to Object
- Next by Date: Re: Why Java's math expression (power) is so inconvenient and error prone?
- Previous by thread: Re: How do I get this to output 12 strings per line
- Next by thread: JNI Woes
- Index(es):