Question

String result = String.format( "% % % | %-20s| %25s | $%,8.2f | %5d | %-s", thisYear, thisMonth, thisDay, 
                    eventName, eventVenue, ticketPrice, ticketsRemaining, eventType);

ints: thisYear, thisMonth, thisDay, ticketsRemaining.

Strings: eventName, eventVenue, eventType.

double: ticketPrice.

I have verified that all the fields are properly initialized. This line should output to this format:

2012-01-20 | Penguins-Capitals    |      CONSOL Energy Center | $   92.35 |    15 | NHL
2012-08-05 | Chickenfoot          |    Riverplex Amphitheatre | $   62.50 | 1,273 | Concert

The formatter is not complete, but I get failures when I try to run it, so there is some syntax error in there. I am not very good with formatter.

Was it helpful?

Solution

You should make sure that you add always the type after %, in this case its %d

String result = String.format( "%4d-%02d-%02d | %-20s| %25s | $%.3f | %5d | %s", thisYear, thisMonth, thisDay, 
                eventName, eventVenue, ticketPrice, ticketsRemaining, eventType);

For making a , instead of a . watch this thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top