String.format
method. It can do a lot.
One thing you might be interested in is something like this:
String form="%1$"+maxLen+"d";
String output=String.format(form,theNum);
maxLen
is the space that every value in the String
is suppose to take up. (You still need to write the algorithm and code to find
that based on the entries in the MathMatrix
object.
The documentation (link below) can tell you all you want to know, but in this case,
"%1$"
means that I'm interested in the first
variable after the format string (form). 'maxLen'
is an int that I
created that tells how many spaces to use when creating the string. 'd'
means that 'theNum'
is an integer. 'theNum'
is an
integer that will be inserted into a String
returned by the String.format
function.
maxLen=6
and theNum=-23
, output=" -23"
.
Joseph Cooper (Former CS307 TA)