I'm learning Java and have spent way too much time on this stupid little problem. I'm trying to dynamically pad the left side of my string outputs with spaces, so all values displayed will be padded left. The problem is, I don't know the length of the values until a user enters them.
Here's an example of what I'm trying to do. nLongestString is the length of the longest string I'm displaying, and strValue is the value of the string itself. This doesn't work dynamically at all. If I hardcode a value for nLongestString it works, but I can't do that since I don't always know how long the strings will be.
System.out.printf("%"+nLongestString+"s", strValue + ": ");
Output should look like:
thisisalongstring:
longstring:
short: