Java How To Program 9th Edition Test Bank
Java How To Program 9th Edition Test Bank
Test Bank for Java How to Program 9th Edition by Paul Deitel
Harvey Deitel
2.2 Q1: End-of-line comments that should be ignored by the compiler are denoted using
a. Two forward slashes ( // ).
b. Three forward slashes ( /// ).
c. A slash and a star ( /* ).
d. A slash and two stars ( /** ).
e. ANS: a. Two forward slashes ( // ).
2.2 Q3: Which of the following cannot cause a syntax error to be reported by the Java
compiler?
a. Mismatched {}
b. Missing */ in a comment that begins with /*
c. Missing ;
d. An extra blank line.
ANS: d. Extra blank lines.
2.2 Q4: Which of the following does not contain a syntax error?
a. [Link]( 'Hello world!' ):
b. [Link]( "Hello
world!" );
c. [Link]( "Hello world!" );
d. [Link]( Hello world! );
ANS: c. [Link]( "Hello world!" );
2.2 Q5: Which command compiles the Java source code file [Link]?
a. cd [Link]
b. javac [Link]
c. java [Link]
d. compile [Link]
ANS: b. javac [Link]
2.2 Q6: Which command executes the Java class file [Link]?
a. javac [Link]
b. java [Link]
c. java Welcome
d. run [Link]
ANS: c. java Welcome
© Copyright 1992-2012 by Deitel & Associates, Inc. and Pearson Education, Inc.
Section 2.3 Modifying Your First Java Program
Displaying a Single Line of Text with Multiple Statements
2.3 Q3: Which of the following statements will print a single line containing
"hello there"?
a. [Link]( "hello" );
[Link]( " there" );
b. [Link]( "hello" , " there" );
c. [Link]( "hello" );
[Link]( " there" );
d. [Link]( "hello" );
[Link]( " there" );
ANS: d. [Link]( "hello" );
[Link]( " there" );
2.3 Q4: Which of the following escape sequences represents a carriage return?
a. \n.
b. \r.
c. \cr.
d. \c.
ANS: b. \r.
2.3 Q5: Which of the following statements would display the phase Java is fun?
a. [Link]( "hellois fun\rJava " );
b. [Link]( 'Java is fun' );
c. [Link]( "\"Java is fun\"" );
d. [Link]( Java is fun );
ANS: a. [Link]( "hellois fun\rJava " );
© Copyright 1992-2012 by Deitel & Associates, Inc. and Pearson Education, Inc.
Section 2.4 Displaying Text with printf
2.4 Q1: When method printf requires multiple arguments, the arguments are separated
with ________.
a. colons (:).
b. semicolons (;).
c. commas (,).
d. periods (.).
ANS: c. commas (,).
2.5 Q3: A(n) ________ enables a program to read data from the user.
a. printf.
b. import declaration.
c. Scanner.
d. main.
ANS: c. Scanner.
© Copyright 1992-2012 by Deitel & Associates, Inc. and Pearson Education, Inc.
2.5 Q5: The format specifier ________ is a placeholder for an int value?
a. %a
b. %d
c. %int
d. %s
ANS: b. %d
2.6 Q1: Which of the following statements does not alter a memory location?
a. int a;
b. number = 12;
c. y = y + 2;
d. width = [Link](input);
ANS: a. int a;
2.7 Q1: What is the value of result after the following Java statements execute?
int a, b, c, d, result;
a = 4;
b = 12;
c = 37;
d = 51;
result = d % a * c + a % b + a;
a. 119
b. 51
c. 127
d. 59
ANS: a. 119
2.8 Q1: What will be output after the following Java statements have been executed?
int a, b, c, d;
a = 4;
© Copyright 1992-2012 by Deitel & Associates, Inc. and Pearson Education, Inc.
b = 12;
c = 37;
d = 51;
if ( a < b )
[Link]( "a < b" );
if ( a > b )
[Link]( "a > b" );
if ( d <= c )
[Link]( "d <= c" );
if ( c != d )
[Link]( "c != d" );
a. a < b
c != d
b. a < b
d <= c
c != d
c. a > b
c != d
d. a < b
c < d
a != b
ANS: a. a < b
c != d
© Copyright 1992-2012 by Deitel & Associates, Inc. and Pearson Education, Inc.