I've been looking around at a lot of questions about the System.out.printf in java for formatting string outputs and I just don't seem to understand how to use it.
I'm trying to print nice columns that looks like this
601 GoPro Hero5 Black 276.95
602 GoPro Hero5 Session 199.00
611 Canon EOS Rebel 361.89
but the best I can get is this
601 GoPro Hero5 Black 276.95
602 GoPro Hero5 Session 199.00
611 Canon EOS Rebel 361.89
I seem to be able to align the first two values but never the third. Here is my code
System.out.printf("%-1s %10s %10.2f\n", "ex string", "ex string", 276.95);
I thought the "-1s" was left align for minus, and 1 would be the space between the first and second input, then %10s would be ten characters apart, the %10.2 would be ten apart with 2 decimal places. So I tried to do
System.out.printf("%-1s %10s %20.2f\n", "ex string", "ex string", 276.95);
but this still doesn't get those third values inline with one another.
Revised attempt using
System.out.printf("%-10s %-10s %10.2f\n", "ex string", "ex string", 276.95);
results in...
601 GoPro Hero5 Black 276.95
602 GoPro Hero5 Session 199.00
611 Canon EOS Rebel 361.89
for the record my code is getting the variables like this:
System.out.printf("%-10s %-10s %10.2f\n", items.get(i).getItemNumber(), items.get(i).getName(), items.get(i).getPrice());