Pepper Pepper - 1 year ago 28
Java Question

How do I format the following String in Java

So, I have the following piece of code has an example:

StringBuilder sb = new StringBuilder (" ");

for (int i = 0; i < 20; i++)
sb.append(" " + i);


for (int i = 0; i < 20; i++) {
sb.append(i + " ");

for (int j = 0; j < 20; j++)
if (j % 2 == 0)
sb.append("A ");

sb.append("B ");



As I go further printing the A's and B's they won't stay under their respective number and the whole text starts to look bad. I was told I could use the Format class to solve this problem but I see no way to do it. I was wondering if you could help me! Thank you.

Riz Riz

Use tabs, like


Do the same for the headings , to keep them in line