Page 227 - Introduction to Programming with Java: A Problem Solving Approach
P. 227

                }
"-----", "-------", "------",
System.out.printf(DATA_FMT_STR,
System.out.printf(DATA_FMT_STR,
// end main
"------");
<addcodehere>); <addcodehere>);
Value
------
280,000
2,300,025
int qty1 = 10;
double price1 = 27999.99;
String item2 = "MINI Cooper";
int qty2 = 100;
double price2 = 23000.25;
System.out.printf(HEADING_FMT_STR,
"Item", "Quantity", "Price", "Value");
System.out.printf(HEADING_FMT_STR,
} // end class CarInventoryReport
Output:
Item Quantity Price
----- --------- ------
9. [after §5.8] Provide a statement that uses Math.Random to generate the total number of dots on a rolled pair of dice.
          Apago PDF Enhancer
Review Question Solutions
1. perimeter = Math.PI * diameter;
2. The class that contains the abs, min, and round methods is: b) Math
3. num = Double.POSITIVE_INFINITY;
4. num = Long.parseLong(s);
5. numStr = Integer.toString(num);
6. Here is the code fragment’s output:
Review Question Solutions 193
 Mazda RX-8
MINI Cooper
10 28,000
100 23,000
 false
true
b
7. System.out.println(snyder.substring(snyder.indexOf('G')));
8. "%-20s%10d%16.6e\n" or
"%-20s%10d%16e\n"
(It’s OK to omit the .6 because the e conversion specifier prints 6 decimal places by default.)
9. "%(,.0f" or
"%,(.0f"
(The order of flag specifier characters is irrelevant.)
  



















































   225   226   227   228   229