Hello I want to print something so they are aligned.
for (int i = 0; i < temp.size(); i++) {
//creatureT += "[" + temp.get(i).getCreatureType() + "]";
creatureS = "\t" + temp.get(i).getName();
creatureT = " [" + temp.get(i).getCreatureType() + "]";
System.out.printf(creatureS + "%15a",creatureT + "\n");
}
and the output is
Lily [Animal]
Mary [NPC]
Peter [Animal]
Squash [PC]
I just want the [Animal], [NPC], and [PC] to be aligned like
Lily [Animal]
Mary [NPC]
Peter [Animal]
Squash [PC]
Say I know that no name will be greater then 15 characters.
I think you’ll find it’s a lot easier to do all of the formatting in the format string itself, i.e.
which would print
You can consult the String formatting documentation on the exact format to use to print a minimum of 15 spaces for a string to achieve the alignment effect, something like
The key is specifying a “width” of 15 chars for the first item in the argument list in
%15s.