This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: double amountOwed = cost + tax; // print amount owed with 2 places after the decimal point // allow a field of width 5 for the amount System.out.printf("Total owed: %5.2f", amountOwed); Output: Total owed: 4.88 Note: The width of the field is the total number of characters to be printed: one space the digit 4 the decimal point two digits after the decimal point Example: System.out.printf("%-7s%5.2f%n", "Tax:", tax); Now we have 3 format specifiers: %-6s: s indicates a string, the hyphen is a flag which means left alignment, and %n is an end of line specifier...
View Full Document
This note was uploaded on 02/24/2010 for the course C S 305j taught by Professor Staff during the Spring '08 term at University of Texas at Austin.
- Spring '08