Hi,
I do not know how to resolve this, I used "-"flag but it does seem change anything.
The point of a whole task is to left-justify a column and later to right-justify.
Any ideas?
public class TestStringFormatting { public static void main(String[] args) { String a ="my dog barks,my cat does not"; String b ="yellow cushions, red carpet"; String c ="window, chair, table"; String d ="pillow, tea"; //left justified System.out.printf("%-1s%n",a); System.out.printf("%-1s%n",b); System.out.printf("%-1s%n",c); System.out.printf("%-1s%n",d); //right justified System.out.printf("%1$1s%n",a); System.out.printf("%1s%n",b); System.out.printf("%1s%n",c); System.out.printf("%1s%n",d); } }
Output:
my dog barks,my cat does not
yellow cushions, red carpet
window, chair, table
pillow, tea
my dog barks,my cat does not
yellow cushions, red carpet
window, chair, table
pillow, tea
Press any key to continue . . .