Doing header with columns

can someone explain me why this line of code:

System.out.printf("%-6s", "Num", "%-10s", "Nome", "%-18s", "Idade Automóvel", "%-15s", "Total de Prémios");

Does this:


Instead of this:

Num    Nome     Idade Automóvel     Total de Prémios


Only first argument represents formatting all other arguments are just data to be used in places as speciffied with format string. You should write it like this:

System.out.printf("%-6s %-10s %-18s %-15s", "Num", "Nome", "Idade Automóvel", "Total de Prémios");

Leave a Reply

Your email address will not be published. Required fields are marked *