I am trying to format strings so that it prints out with a width of three always and ending at the same line despite how large the number is. Every number but one is a decimal below ten; however, when I print the one above ten that is a decimal the width is four and ends past the last digit of the previous numbers. I would like to make it so that they all end at the same spot and line up on the right by that. How can I do this using printf in Java?
[a 4.34]
[b 0.32]
[c 12.52]
I would like each of those to line up like so
[a 4.34]
[b 0.32]
[c 12.5]
Here is what I already have for the line that prints
for(int i = 0; i < 26;i++)
{
System.out.printf("[%c %3.2f]\n", letters[i], frequencies[i]);
}
Thanks!