Let's say I have a couple variable and I want to format them so they're all aligned, but the variables are different lengths. For example:
String a = "abcdef";
String b = "abcdefhijk";
And I also have a price.
double price = 4.56;
How would I be able to format it so no matter how long the String is, they are aligned either way?
System.out.format("%5s %10.2f", a, price);
System.out.format("%5s %10.2f", b, price);
For example, the code above would output something like this:
abcdef 4.56
abcdefhijk 4.56
But I want it to output something like this:
abcdef 4.56
abcdefhijk 4.56
How would I go about doing so? Thanks in advance.