Absolute Java 5th Edition by Walter Savitch - Test Bank
Chapter 2
Console Input and Output
Multiple Choice
1)
Valid
arguments to the System.out object’s println method include:
(a) “Anything with double quotes”
(b) String variables
(c) Variables of type int
(d) All of the above
Answer:
D
2)
Which
statement or group of statements produces the output: Java programming is fun!
(a)
System.out.print(Java
programming);
System.out.print(is fun!);
(b)
System.out.println(Java
programming is fun!);
(c)
System.out.println(“Java
programming”);
System.out.println(“ is fun!”);
(d)
System.out.print(“Java
programming”)
System.out.println(“ is fun!”);
Answer:
D
3)
If a
hyphen is added after the % in a format specifier, the output will be
_________.
(a)
Left
justified
(b)
Right
justified
(c)
Centered
(d)
None of
the above
Answer:
A
4)
The
statement: System.out.printf("%6.2f", 597.7231); displays:
(a)
597.723
(b)
597.72
(c)
000597.72
(d)
None of
the above
Answer:
B
5)
The Java
method printf is based on the ________ language.
(a)
Pascal
(b)
C++
(c)
C
(d)
ADA
Answer:
C
6)
The class
NumberFormat allows you to specify a constant representing which country’s
currency format should be used. To use
this constant you must import:
(a)
java.util.Locale
(b)
java.util.Currency
(c)
java.util.Properties
(d)
None of
the above.
Answer:
A
7)
Standard
code libraries in Java are called:
(a)
Methods
(b)
Classes
(c)
Packages
(d)
Statements
Answer:
C
8)
What does
the following code output?
DecimalFormat percent = new
DecimalFormat("0.00%");
System.out.println(percent.format(0.308));
(a)
3.080%
(b)
30.80%
(c)
.0308%
(d)
308.0%
Answer:
B
9)
What does
the following code output?
DecimalFormat dfQuestion = new
DecimalFormat("#0.##E0");
System.out.println(dfQuestion.format(12.7896987));
(a)
12.79E0
(b)
12.8E0
(c)
1.28E1
(d)
.13E2
Answer:
A