Chapter 15 JAVA Flashcards
Which of the following is the most general form of printf()
A. printf(locale, formatString, value1, value2, value3, …)
B. printf(locale, formatString )
C. printf( value1, value2, value3, …)
D. printf( format1, format2, format3, …)
A. printf(locale, formatString, value1, value2, value3, …)
What does the following print?
double value= -486.1234;
System.out.printf(“value=%8.2f%n”, value);
(The small dots ….in some answers show where spaces are printed.)
A.
value=-486.1234
B.
value= -486.12
C.
value= -486.12n
D.
value=….-486.12
B.
value= -486.12
What does the following print?
double value= 486.1999;
System.out.printf(“value=%10.1f%n”, value);
A.
value=……486.1
B.
value=….486.1999
C.
value=…..486.2
D.
value=486.12
C.
value=…..486.2
What does the following print?
int sum = 3487;
System.out.printf(“sum=%10d%n”, sum);
A.
sum=……3487
B.
sum= 3487
C.
sum=……….3487
D.
sum=3487.0
A.
sum=……3487
What does the following print?
int sum = 3487;
System.out.printf(“sum=%010d%n”, sum);
A.
sum=0000003487
B.
sum=03487
C.
sum=00000000003487
D.
sum=03487
A.
sum=0000003487
What does the following print?
int sum = 3487174;
System.out.printf(“sum=%3d%n”, sum);
A.
sum=348
B.
sum=174
C.
sum=3487174
D. An Exception will halt the program.
C.
sum=3487174
What does the following print?
int sum = 10034;
System.out.printf(“sum=%8.2f%n”, sum);
A.
sum=10034.00
B.
sum=…10034
C.
sum=00010034
D. An Exception will halt the program.
D. An Exception will halt the program.
What does the following print?
int balance=987654321;
System.out.printf(Locale.US, “balance:%,12d%n”, balance);
A.
balance: 987654321
B.
balance: 987 654 321
C.
balance: 987,654,321
D.
balance:…987,654,321
C.
balance: 987,654,321
. What does the following print?
String coins=”dimes”; int number=19 ;
double unitValue=0.10;
System.out.printf( “You have %d %s worth %5.2f dollars%n”, number, coins, number*unitValue );
A.
You have 19 dimes worth..1.90 dollars
B.
You have19dimes worth1.90dollars
C.
You have…19…dimes worth….1.90 dollars
D.
You have 19….dimes….worth 1.9 dollars
A.
You have 19 dimes worth..1.90 dollars
What does the following print?
System.out.printf( “|%-10s%10s|%n”, “Hello”, “World” );
A.
|HelloWorld|
B.
|Hello…..World…..|
C.
|Hello……….World|
D.
Hello World |
C.
|Hello……….World|