Full file at

Similar documents
4. If the following Java statements are executed, what will be displayed?

Starting Out with Java: From Control Structures through Data Structures 3e (Gaddis and Muganda) Chapter 2 Java Fundamentals

Gaddis: Starting Out with Java: From Control Structures through Objects, 6/e

Computational Expression

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Getting started with Java

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Elementary Programming

Oct Decision Structures cont d

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Lec 3. Compilers, Debugging, Hello World, and Variables

Datatypes, Variables, and Operations

Full file at

Decisions in Java IF Statements

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

CMSC131. Introduction to your Introduction to Java. Why Java?

Key Differences Between Python and Java

Programming with Java

Lecture Set 2: Starting Java

CHAPTER 2 Java Fundamentals

Lecture Set 2: Starting Java

LECTURE 02 INTRODUCTION TO C++

Please answer the following questions. Do not re-code the enclosed codes if you have already completed them.

Chapter 2: Java Fundamentals

8/23/2014. Chapter Topics. Chapter Topics (2) Parts of a Java Program. Parts of a Java Program. Analyzing The Example. Chapter 2: Java Fundamentals

Entry Point of Execution: the main Method. Elementary Programming. Compile Time vs. Run Time. Learning Outcomes

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Fundamentals of Programming Data Types & Methods

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4

Peer Instruction 1. Elementary Programming

Chapter 2: Introduction to C++

Object-Oriented Programming

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

4 Programming Fundamentals. Introduction to Programming 1 1

Introduction to Java & Fundamental Data Types

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

Java Bytecode (binary file)

Chapter 2: Programming Concepts

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

CS 302: Introduction to Programming

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Basic Computation. Chapter 2

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Software and Programming 1

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Conditional Execution

Chapter 2 Elementary Programming

Chapter 4: Control Structures I

Section 2.2 Your First Program in Java: Printing a Line of Text

Lecture 2 Tao Wang 1

Chapter 2 ELEMENTARY PROGRAMMING

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Java Identifiers, Data Types & Variables

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Chapter 4: Loops and Files

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

What did we talk about last time? Examples switch statements

Section 2.2 Your First Program in Java: Printing a Line of Text

SOFT 161. Class Meeting 1.6

Array. Prepared By - Rifat Shahriyar

Java Basic Programming Constructs

Basics of Java Programming

First Java Program - Output to the Screen

Elementary Programming. CSE 114, Computer Science 1 Stony Brook University

Basic Computation. Chapter 2

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

CSE 1223: Exam II Autumn 2016

CHAPTER 3 BASIC INSTRUCTION OF C++

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Chapter 2 Primitive Data Types and Operations. Objectives

Selected Questions from by Nageshwara Rao

Question: Total Points: Score:

Chapter 2 Primitive Data Types and Operations

Software and Programming 1

Full file at

AP Computer Science Unit 1. Programs

The C++ Language. Arizona State University 1

Chapter 4: Loops and Files

CS Week 5. Jim Williams, PhD

Using Java Classes Fall 2018 Margaret Reid-Miller

COMP 202 Java in one week

Darrell Bethea May 10, MTWRF 9:45-11:15 AM Sitterson 011

Important Java terminology

CSc 2010 Principles of Computer Science, Fall 2013 Practice Problems for Midterm 3* * 3 17 % 9-20 % (26 / 7) "2"

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M.

Zheng-Liang Lu Java Programming 45 / 79

CEN 414 Java Programming

1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d.

Transcription:

Gaddis: Starting Out with Java: Early Objects, 4/e Test Bank 1 Chapter 2 Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Which of the following is not a valid comment statement? 1) A) /** comment 4 B) /* comment 2 */ C) */ comment 3 /* D) // comment 1 2) When saving a Java source file, save it with an extension of 2) A).java B).javac C).src D).class 3) What will be displayed as a result of executing the following code? int x = 8; String msg = "I am enjoying java."; String msg1 = msg.touppercase(); String msg2 = msg.tolowercase(); char ltr = msg.charat(x); int strsize = msg.length(); System.out.println(msg); System.out.println(msg1); System.out.println(msg2); System.out.println("Character at index x = " + ltr); System.out.println("msg has " + strsize + " characters."); A) I am enjoying java. I AM ENJOYING JAVA. i am enjoying java. Character at index x = j msg has 20 characters. C) I am enjoying java.i AM ENJOYING JAVA.i am enjoying java.character at index x = omsg has 19 characters. B) I am enjoying java. I AM ENJOYING JAVA. i am enjoying java. Character at index x = o msg has 20 characters. D) I am enjoying java. I AM ENJOYING JAVA. i am enjoying java. Character at index x = y msg has 19 characters. 3) 4) This is a value that is written into the code of a program. 4) A) literal B) operator C) assignment statement D) variable 5) Which of the following is not a rule that must be followed when naming identifiers? 5) A) After the first character, you may use the letters a-z, A-Z, the underscore, a dollar sign, or digits 0-9. B) Identifiers can contain spaces. C) Uppercase and lowercase characters are distinct. D) The first character must be one of the letters a-z, A-Z, and underscore or a dollar sign. 6) Character literals are enclosed in ; string literals are enclosed in. 6) A) single quotes; double quotes B) double quotes; single quotes

Gaddis: Starting Out with Java: Early Objects, 4/e Test Bank 2 C) single quotes; single quotes D) double quotes; double quotes 7) What is the result of the following statement? 17 % 3 * 2-12 + 15 A) 105 B) 12 C) 8 D) 7 7) 8) What will be the value of z after the following statements have been executed? 8) int x = 4, y = 33; double z; z = (double) (y / x); A) 8.0 B) 4 C) 0 D) 8.25 9) What is the result of the following expression? 10 + 5 * 3-20 A) -5 B) -50 C) 5 D) 25 9) 10) Variables are classified according to their. 10) A) names B) location in the program C) value D) data type 11) Which of the following will correctly convert the data type, if x is a float and y is a double? 11) A) x = float y; B) x = <float>y; C) x = y; D) x = (float)y; 12) The boolean data type may contain values in the following range of values 12) A) -128 to +127 B) true or false C) -32,768 to +32,767 D) -2,147,483,648 to +2,147,483,647 13) What will be displayed as a result of executing the following code? int x = 5, y = 20; x += 32; y /= 4; System.out.println("x = " + x + ", y = " + y); 13) A) x = 160, y = 80 B) x = 32, y = 4 C) x = 37, y = 5 D) x = 9, y = 52 14) This is a named storage location in the computer's memory. 14) A) operator B) constant C) variable D) literal 15) Given the declaration double r;, which of the following statements is invalid? 15) A) r = 9.4632E15; B) r = 326.75; C) r = 9.4632e15; D) r = 2.9X106;

Gaddis: Starting Out with Java: Early Objects, 4/e Test Bank 3 16) To print "Hello, world" on the monitor, use the following Java statement 16) A) SystemOutPrintln("Hello, world"); B) Print("Hello, world"); C) System.out.println{"Hello, world"} D) System.out.println("Hello, world"); 17) Variables of the boolean data type are useful for 17) A) evaluating true/false conditions B) working with very large integers C) working with small integers D) evaluating scientific notation 18) What would be displayed as a result of the following code? 18) int x = 578; System.out.print("There are " + x + 5 + "\n" + "hens in the hen house."); A) There are 583 hens in the hen house. B) There are 5785 hens in the hen house. C) There are x5\nhens in the hen house. D) There are 5785 hens in the hen house. 19) In the following Java statement what value is stored in the variable name? String name = "John Doe"; A) "name" B) The memory address where "John Doe" is located C) The memory address where name is located D) "John Doe" 19) 20) What will be the displayed when the following code is executed? final int x = 22, y = 4; y += x; System.out.println("x = " + x + ", y = " + y); A) x = 22, y = 26 B) x = 22, y = 4 C) x = 22, y = 88 D) Nothing, this is an error 20) 21) A Java program must have at least one 21) A) Comment B) System.out.println(); statement C) Class definition D) Variable 22) What will be displayed after the following statements have been executed? int x = 15, y = 20, z = 32; x += 12; y /= 6; z - = 14;

Gaddis: Starting Out with Java: Early Objects, 4/e Test Bank 4 System.out.p rintln ("x = " + x + ", y = " + y + ", z = " + z); 22) A) x = 27, y = 3, z = 18 B) x = 37, y = -14, z = 4 C) x = 27, y = 3.333, z = 18 D) x = 27, y = 2, z = 18 23) Which of the following statements correctly creates a Scanner object for keyboard input? 23) A) Scanner kbd = new Scanner(System.keyboard); B) Scanner keyboard = new Scanner(System.in); C) Scanner keyboard(system.in); D) Keyboard scanner = new Keyboard(System.in); 24) What will be the value of z as a result of executing the following code? 24) int x = 5, y = 28; float z; z = (float) (y / x); A) 5.60 B) 5.0 C) 5.6 D) 3.0 25) The primitive data types only allow a(n) to hold a single value. 25) A) variable B) class C) literal D) object 26) Which Scanner class method reads a String? 26) A) nextline B) getstring() C) readstring() D) nextstring() 27) What will be displayed as a result of executing the following code? public class test { public static void main(string[] args) { int value1 = 9; System.out.println(value1); int value2 = 45; System.out.println(value2); System.out.println(value3); 27) val ue = 16; } }

Gaddis: Starting Out with Java: Early Objects, 4/e Test Bank 5 A) 94516 B) 9 45 16 C) 9 45 16 D) Nothing, this is an error 28) This is normally considered the standard output and standard input devices, and usually refer to the monitor and keyboard. A) console B) CRT C) secondary storage devices D) CPU 28) 29) What would be printed out as a result of the following code? 29) System.out.println("The quick brown fox" + "jumped over the \n" "slow moving hen."); A) The quick brown fox jumped over the \nslow moving hen. B) The quick brown fox jumped over the slow moving hen. C) The quick brown fox jumped over the slow moving hen. D) Nothing. This is an error. 30) Which of the following is not a primitive data type? 30) A) short B) long C) String D) float 31) Which of the following does not describe a valid comment in Java? 31) A) Documentation comments, any comments starting with /** B) Multi-line comments, start with */ and end with /* C) Single line comments, two forward slashes - // D) Multi-line comments, start with /* and end with */ 32) To display the output on the next line, you can use the println method or use this escape sequence in the print method. A) \r B) \n C) \t D) \b 32) 33) If the following Java statements are executed, what will be displayed? 33) System.out.println("The top three winners are\n"); System.out.print("Jody, the Giant\n"); System.out.print("Buffy, the Barbarian"); System.out.println("Adelle, the Alligator");

Gaddis: Starting Out with Java: Early Objects, 4/e Test Bank 6 A) The top three winners are Jody, the Giant\nBuffy, the BarbarianAdelle, the Alligator B) The top three winners are Jody, the Giant Buffy, the Barbarian Adelle, the Alligator C) The top three winners are Jody, the Giant Buffy, the BarbarianAdelle, the Alligator D) The top three winners are Jody, the Giant\nBuffy, the BarbarianAdelle, and the Alligator 34) If x has been declared an int, which of the following is invalid? 34) A) x = 0; B) x = 592; C) x = -58932; D) x = 1,000; 35) Which of the following is a valid Java statement? 35) A) string str = "John Doe"; B) String str = 'John Doe'; C) string str = 'John Doe'; D) String str = "John Doe"; 36) What will be displayed as a result of executing the following code? int x = 6; String msg = "I am enjoying this class."; String msg1 = msg.touppercase(); String msg2 = msg.tolowercase(); char ltr = msg.charat(x); int strsize = msg.length(); System.out.println(msg); System.out.println(msg1); System.out.println(msg2); System.out.println("Character at index x = " + ltr); System.out.println("msg has " + strsize + "characters."); A) I am enjoying this class. I AM ENJOYING THIS CLASS. i am enjoying this class. Character at index x = n msg has 24 characters. C) I am enjoying this class. I AM ENJOYING THIS CLASS. i am enjoying this class. Character at index x = e msg has 25 characters. B) I am enjoying this class. I AM ENJOYING THIS CLASS. i am enjoying this class. Character at index x = n msg has 25 characters. D) I am enjoying this class. I AM ENJOYING THIS CLASS. i am enjoying this class. Character at index x = e msg has 24 characters. 36) 37) Which of the following is valid? 37) A) float y; z 934.21; B) float w; C) double v; double z; = y = z; w = 1.0f; v = 1.0f;

Gaddis: Starting Out with Java: Early Objects, 4/e Test Bank 7 D) float y; y = 54.9; 38) Every Java application program must have 38) A) a class named MAIN B) integer variables C) comments D) a method named main 39) To compile a program named, First, use the following command 39) A) javac First.java B) java First.java C) javac First D) compile First.javac 40) What is the result of the following statement? 25/4 + 4 * 10 % 3 A) 19 B) 3 C) 5.25 D) 7 40) 41) Which Scanner class method reads an int? 41) A) readint() B) getint() C) read Int() D) nextint() 42) What will be displayed after the following statements have been executed? final double x; x = 54.3; System.out.println("x = " + x ); A) x B) x = 54.3 C) x = 108.6 D) Nothing, this is an error. 42) 43) This is a variable whose content is read only and cannot be changed during the program's execution of the program. A) operator B) reserved word C) named D) literal constant 43) 44) What is the result of the following expression? 25-7 * 3 + 12/3 A) 12 B) 8 C) 10 D) 6 44) TRUE/FALSE. Write 'T' if the statement is true and 'F' if the statement is false. 45) Programming style includes techniques for consistently putting spaces and indentation in a program so visual cues are created. 45) 46) Assuming that pay has been declared a double, the following statement is valid. pay =

Gaddis: Starting Out with Java: Early Objects, 4/e Test Bank 8 2,583.44; 46) 47) Both character literals and string literals can be assigned to a char variable. 47) 48) All Java lines of code end with semicolons. 48) 49) A variable's scope is the part of the program that has access to the variable. 49) 50) In Java the variable named One is the same as the variable named ONE. 50) 51) Identifiers and class names are examples of variables. 51) 52) If the compiler encounters a statement that uses a variable before the variable is declared, an error will result. 52) 53) Named constants are initialized with a value, that value cannot be changed during the execution of the program. 53) 54) A variable's scope is the part of the program that has access to the variable. 54)

Gaddis: Starting Out with Java: Early Objects, 4/e Test Bank 9 1) C 2) A 3) C 4) A 5) B 6) A 7) D 8) A 9) C 10) D 11) D 12) B 13) C 14) C 15) D 16) D 17) A 18) B 19) B 20) D 21) C 22) A 23) B 24) B 25) A

Gaddis: Starting Out with Java: Early Objects, 4/e Test Bank 10 26) A 27) D 28) A 29) D 30) C 31) B 32) B 33) C 34) D 35) D 36) B 37) B 38) D 39) A 40) D 41) D 42) D 43) C 44) B 45) TRUE 46) FALSE 47) FALSE 48) FALSE 49) TRUE 50) FALSE

Gaddis: Starting Out with Java: Early Objects, 4/e Test Bank 11 51) FALSE 52) TRUE 53) TRUE 54) TRUE