Deck 2: Console Input and Output
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/29
Play
Full screen (f)
Deck 2: Console Input and Output
1
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
(a)Left justified
(b)Right justified
(c)Centered
(d)None of the above
A
2
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
(a)"Anything with double quotes"
(b)String variables
(c)Variables of type int
(d)All of the above
D
3
Efficiency is lost in importing the entire package instead of importing the classes you use.
False
4
The Scanner class has a method next that allows an entire line of string text to be read.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
5
Write Java statements to apply currency formatting to the number 100.Indicate the package you need to import.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
6
Every Java program automatically imports the java.util package.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
7
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!");
(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!");
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
8
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.
(a)java.util.Locale
(b)java.util.Currency
(c)java.util.Properties
(d)None of the above.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
9
The Java method printf is based on the ________ language.
(a)Pascal
(b)C++
(c)C
(d)ADA
(a)Pascal
(b)C++
(c)C
(d)ADA
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
10
Standard code libraries in Java are called:
(a)Methods
(b)Classes
(c)Packages
(d)Statements
(a)Methods
(b)Classes
(c)Packages
(d)Statements
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
11
Echoing input is good programming practice because it can reveal problems in the input.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
12
What Java package includes the class Scanner?
(a)awt
(b)swing
(c)io
(d)util
(a)awt
(b)swing
(c)io
(d)util
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
13
Write a Java statement to display your name in the console window.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
14
The method printf is used the same way as the method println but has the added feature that allows you to add formatting instructions.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
15
The statement: System.out.printf("%6.2f",597.7231); displays:
(a)597.723
(b)597.72
(c)000597.72
(d)None of the above
(a)597.723
(b)597.72
(c)000597.72
(d)None of the above
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
16
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%
DecimalFormat percent = new DecimalFormat("0.00%");
System.out.println(percent.format(0.308));
(a)3.080%
(b)30.80%
(c))0308%
(d)308.0%
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
17
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
DecimalFormat dfQuestion = new DecimalFormat("#0.##E0");
System.out.println(dfQuestion.format(12.7896987));
(a)12.79E0
(b)12.8E0
(c)1.28E1
(d))13E2
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
18
The new line character is represented as '\n'.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
19
The printf method can be used to output multiple formatted values.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
20
Write ONE Java statement to display your first and last name on two separate lines.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
21
What does it mean to prompt the user?
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
22
Write a Java statement to create and initialize a Scanner object named input.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
23
What do the format specifiers d,f,e,g,s and c represent?
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
24
Write a Java program to create and display 57.32% using the DecimalFormat class.Include the necessary import statement to use the DecimalFormat class.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
25
If there is no loss of efficiency in importing an entire Java package instead of importing only classes you use into your program,why would you not just import the entire package?
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
26
Write a complete Java console application that prompts the user for two numbers,multiplies the numbers,and then displays the result to the user.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
27
Why is echoing user input a good programming practice?
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
28
What is whitespace and why is it import when reading input from the keyboard using the Scanner class?
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
29
Explain the significance of the pattern string used by the DecimalFormat object,and give an example of a valid pattern.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck