I want to create something like this, where each line is surrounded by a "pipe" char.
| First Line | | 100 200 | | 1000 2000 |
- In the first line, the right filling is 1 space.
- In the second line, the correct filling is 4 spaces.
- The third line contains 2 spaces.
I am trying to do this with printf + formating (and not explicitly calculating the fill number), but I am having some problems with the syntax of the formation. Here is my current code:
System.out.printf("| FIRST LINE" + "%50s\n", "|"); System.out.printf("| 100 200" + "%50s", "|"); System.out.printf("| 1000 2000" + "%50s", "|");
I am trying to indicate that the maximum per line is 50 characters, which is the first character in the string "pipe" and the last character in the string is another "pipe").
The problem is that 50 spaces are placed without considering the characters already in use on the left side (that is, "| FIRST LINE"). The above code is similar to:
System.out.format("%s %50s\n", "| FIRST LINE", "|");
So, how can I define the output format so that both lines are counted for the width?
Thanks in advance.
source share