Java How to Program, 11/e Multiple Choice Test Bank Page 4 of 7
Section 2.5.3 Prompting the User for Input
2.5.5 Q1: Which of the following statements is true?
a. System.out.print(“Enter your age: “); prompts the user to take action.
b. Class names typically begin with a capital letter.
c. Package java.lang is imported in every Java program.
d. All of the above are true.
Section 2.5.4 Declaring a Variable to Store an Integer and
Obtaining an Integer from the Keyboard
2.5.4 Q1: Which of the following is not a Java primitive type?
a. char
b. byte
c. real
d. double
2.5.4 Q2: Which of the following statements is false?
a. Primitive types are keywords.
b. Primitive types must appear in all lowercase letters.
c. Real numbers contain decimal points.
d. Variable name identifiers must begin with a lowercase letter.
Section 2.5.5 Obtaining a Second Intege
2.5.6 Q1: Which of the following is a Scanner method for inputting an integer value?
a. nextInteger
b. integer
c. nextInt
d. int
2.5.6 Q2: Given the Java statement
int number1 = input.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.
Section 2.5.6 Using Variables in a Calculation
2.5.8 Q1: Portions of statements that contain calculations are called
a. variables.
b. constants.