I am trying format marry string so they align in the same way e.g.
This is how I would like them to be formatted:
Cricket $100 Football $100 Basketball $1 The total Cost is $201
This is the method I have tried though I get mix results when different inputs are given, sometimes it works sometimes it doesn't.
This is what it mostly ends up like:
Cricket $100 Football $100 Basketball $1 The total Cost is $201
I have tried experimenting by having different right-align in code for total cost though nearly always get wayward results, though it has worked a couple of times on different values of variable length where right-align and left-align were different.
This is the code I have tried:
System.out.printf("%-15s %15s %n", " Cricket", "$100"); System.out.printf("%-15s %15s %n", " Football", "$100"); System.out.printf("%-15s %15s %n", " Basketball", "$1"); System.out.printf("%-15s %15s %n", "The total Cost is", "$201");
I am not bothered about how much spacing there is in between, I just want to align the $ signs as I have managed to align the sports. Where am I going wrong?