MC Ch02 IntroApplication
MC Ch02 IntroApplication
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 (/**).
ANS: a. Two forward slashes (//).
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. An extra blank line.
Q5: Which command compiles the Java source code file Welcome.java?
a. cd Welcome.java
b. javac Welcome.java
c. java Welcome.java
d. compile Welcome.java
ANS: b. javac Welcome.java
Q9: Which of the following statements will print a single line containing
"hello there"?
a. System.out.println("hello");
System.out.println(" there");
b. System.out.println("hello" , " there");
c. System.out.println("hello");
System.out.print(" there");
d. System.out.print("hello");
System.out.println(" there");
ANS: d. System.out.print("hello");
System.out.println(" there");
Q11: Which of the following statements would display the phrase Java is fun?
a. System.out.println("hellois fun\rJava ");
b. System.out.println('Java is fun');
c. System.out.println("\"Java is fun\"");
d. System.out.println(Java is fun);
ANS: a. System.out.println("hellois fun\rJava ");
Q12: When method printf requires multiple arguments, the arguments are separated with ________.
a. colons (:).
b. semicolons (;).
c. commas (,).
d. periods (.).
ANS: c. commas (,).
Q18: A(n) ________ enables a program to read data from the user.
a. printf.
b. import declaration.
c. Scanner.
d. main.
ANS: c. Scanner.
Q22: Which of the following is a Scanner method for inputting an integer value?
a. nextInteger
b. integer
c. nextInt
d. int
ANS: c. nextInt.
in which input is a Scanner, which of the following occurs if the user does not enter a valid int value?
a. A compilation error occurs.
b. The program continues executing and assigns the value 0 to number1.
c. A runtime logic error occurs.
d. None of the above.
ANS: c. A runtime logic error occurs.
Q28: Which of the following statements does not alter the value stored in a memory location?
a. int a;
b. number = 12;
c. y = y + 2;
d. width = Integer.parseInt(input);
ANS: a. int a;
Q29: What is the value of result after the following Java statements execute (assume all variables are of type int)?
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
Q31: What will be output after the following Java statements have been executed (assume all variables are of type
int)?
a = 4;
b = 12;
c = 37;
d = 51;
if (a < b) {
System.out.println("a < b");
}
if (a > b) {
System.out.println("a > b");
}
if (d <= c) {
System.out.println("d <= c");
}
if (c != d) {
Chapter 02 Java How to Program, 11/e Multiple Choice Test Bank Page 6 of 6
System.out.println("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