Education > EXAM > QuestionBank_Ch02-10 Java How to Program, 11/e Multiple Choice Test Bank. Chapter 2 Introduction to (All)
Section 2.2 Your First Program in Java: Printing a Line of Text 2.2 Q1: End-of-line comments that should be ignored by the compiler are denoted using a. Two forward slashes (//). b. Three forward s... lashes (///). c. A slash and a star (/*). d. A slash and two stars (/**). ANS: a. Two forward slashes (//). 2.2 Q2: Which of the following is not a valid Java identifier? a. my Value b. $_AAA1 c. width d. m_x ANS: a. my Value (Identifiers may not contain blanks). 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. An extra blank line. 2.2 Q4: Which of the following does not contain a syntax error? a. System.out.println('Hello world!'): b. System.out.println("Hello world!"); c. System.out.println("Hello world!"); d. System.out.println(Hello world!); ANS: c. System.out.println("Hello world!"); Compiling and Executing Your First Java Application 2.2 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 2.2 Q6: Which command executes the Java class file Welcome.class? a. java welcome b. java Welcome.class c. java Welcome d. run Welcome.class ANS: c. java Welcome (Note that you must use the same capitalization as the class name.) Java How to Program, 11/e Multiple Choice Test Bank Page 2 of 66 Page 2 of 66 Section 2.3 Modifying Your First Java Program Displaying a Single Line of Text with Multiple Statements 2.3 Q1: Which is the output of the following statements? System.out.print("Hello "); System.out.println("World"); a. Hello World b. HelloWorld c. Hello World d. World Hello ANS: a. Hello World Displaying Multiple Lines of Text with a Single Statement 2.3 Q2: Which of the following is the escape character? a. * b. \ c. \n d. " ANS: b. \ 2.3 Q3: 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"); 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. 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 "); Java How to Program, 11/e Multiple Choice Test Bank Page 3 of 66 Page 3 of 66 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.4 Q2: Which of the following statement displays Hello World? a. System.out.printf("%2s", "Hello " "World"); b. System.out.printf("%s %s", "Hello", "World"); c. System.out.printf("%s%s", "Hello, World"); d. System.out.printf("s% s%", "Hello", "World"); ANS: b. System.out.printf("%s %s", "Hello", "World"); Section 2.5 Another Application: Adding Integers 2.5 Q1: Programs remember numbers and other data in the computer's memory and access that data through program elements called a. comments. b. messages. c. integers. d. variables. ANS: d. variables. Section 2.5.1 import Declarations 2.5.1 Q1: All import declarations must be placed a. inside the class declaration’s body. b. before the class declaration. c. after the class declaration. d. all of the above will work. ANS: b. before the class declaration. 2.5.1 Q2: Java's predefined classes are grouped into a. packets. b. declarations. c. Galleries. d. packages. ANS: d. packages. Section 2.5.2 Declaring and Creating a Scanner to Obtain User Input from the Keyboard 2.5.3 Q1: Which of the following is a variable declaration statement? a. int total; b. import java.util.Scanner; Java How to Program, 11/e Multiple Choice Test Bank Page 4 of 66 Page 4 of 66 c. public static void main(String args[]) d. // first string entered by user ANS: a. int total; 2.5.3 Q2: A(n) ________ enables a program to read data from the user. a. printf. b. import declaration. c. Scanner. d. main. ANS: c. Scanner. 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. ANS: 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 ANS: c. real 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. ANS: d. Variable name identifiers must begin with a lowercase letter. This is not required, but it is a convention. 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 ANS: c. nextInt. 2.5.6 Q2: Given the Java statement ... [Show More]
Last updated: 1 year ago
Preview 1 out of 66 pages
Connected school, study & course
About the document
Uploaded On
Jul 12, 2022
Number of pages
66
Written in
This document has been written for:
Uploaded
Jul 12, 2022
Downloads
0
Views
49
In Browsegrades, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Browsegrades · High quality services·