Java Reference
In-Depth Information
25 System.out.print(
ÐEnter
nickels: Ñ
);
26
int
nickels = in.nextInt();
27 System.out.print(
ÐEnter
pennies: Ñ
);
28
int
pennies = in.nextInt();
29 register.enterPayment(dollars,
quarters, dimes, nickels, pennies);
30
31 System.out.print(
ÐYour
change: Ñ
);
32 System.out.println(register.giveChange
33 }
34 }
Output
Enter price:
7.55
Enter dollars:
10
Enter quarters:
2
Enter dimes:
1
Enter nickels:
0
Enter pennies:
0
Your change: 3.05
166
167
S
ELF
C
HECK
15.
Why can't input be read directly from
System.in?
16.
Suppose in is a
Scanner
object that reads from
System.in
, and your
program calls
String name = in.next();
What is the value of
name
if the user enters
John Q. Public?
A
DVANCED
T
OPIC
4.6: Formatting Numbers
The default format for printing numbers is not always what you would like. For
example, consider the following code segment:
double total = 3.50;
final double TAX_RATE = 8.5; //
Tax rate in percent