Isambe Isambe - 4 months ago 6x
Java Question

Java printf cheat: Is this legal?

This cheat compiles and runs just fine in NetBeans. However, it seems like it's probably not legal, for a couple of different reasons. Or is it? It could make code a bit more compact in some situations. Just curious.

System.out.printf("%-20d John Smith %n", 12);

...which gives me:

12 John Smith


It's perfectly legal, -20 left aligns twenty spaces and %n is a newline.