Isambe Isambe - 1 year ago 105
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download