Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web...

34
download instant at www.easysemester.com 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 download instant at www.easysemester.com

Transcript of Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web...

Page 1: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comChapter 2 ExamName___________________________________ 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)

download instant at www.easysemester.com

Page 2: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comWhat 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.");

3)

_______ A)

I am enjoying java.I AM ENJOYING JAVA.i am enjoying java.Character at index x = jmsg has 20 characters.

B)

I am enjoying java.I AM ENJOYING JAVA.i am enjoying java.Character at index x = omsg has 20 characters.

C)

I am enjoying java.I AM ENJOYING JAVA.i am enjoying java.Character at index x = omsg has 19 characters.

D)

I am enjoying java.I AM ENJOYING JAVA.i am enjoying java.Character at index x = ymsg has 19 characters.

4)

This is a value that is written into the code of a program.

4)

_______ A)

download instant at www.easysemester.com

Page 3: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comliteral

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 C)

download instant at www.easysemester.com

Page 4: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comsingle quotes; single quotes

D)

double quotes; double quotes

7)

What is the result of the following statement?17 % 3 * 2 - 12 + 15

7)

_______ A)

105

B)

12

C)

8

D)

7

8)

What will be the value of z after the following statements have been executed?

int x = 4, y = 33;double z;z = (double) (y / x);

8)

_______ A)

8.0

B)

4

C)

0

download instant at www.easysemester.com

Page 5: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comD)

8.25

9)

What is the result of the following expression?10 + 5 * 3 - 20

9)

_______ A)

-5

B)

-50

C)

5

D)

25

10)

Variables are classified according to their _____.

10)

______ A)

names

B)

location in the program C)

value

D)

data type

download instant at www.easysemester.com

Page 6: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.com11)

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);

download instant at www.easysemester.com

Page 7: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.com

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)

download instant at www.easysemester.com

Page 8: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comr = 9.4632E15;

B)

r = 326.75; C)

r = 9.4632e15;

D)

r = 2.9X106;

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)

download instant at www.easysemester.com

Page 9: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comworking with small integers

D)

evaluating scientific notation

18)

What would be displayed as a result of the following code?

int x = 578;System.out.print("There are " + x + 5 + "\n" + "hens in the hen house.");

18)

______ A)

There are 583 hens in the hen house.

B)

There are 5785hens 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";

19)

______ A)

"name" B)

The memory address where "John Doe" is located C)

download instant at www.easysemester.com

Page 10: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comThe memory address where name is located

D)

"John Doe"

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);

20)

______ A)

x = 22, y = 26

B)

x = 22, y = 4 C)

x = 22, y = 88

D)

Nothing, this is an error

21)

A Java program must have at least one

21)

______ A)

Comment

B)

System.out.println(); statement C)

Class definition

D)

download instant at www.easysemester.com

Page 11: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comVariable

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;System.out.println("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);

download instant at www.easysemester.com

Page 12: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comD)

Keyboard scanner = new Keyboard(System.in);

24)

What will be the value of z as a result of executing the following code?

int x = 5, y = 28;float z;z = (float) (y / x);

24)

______ 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) download instant at www.easysemester.com

Page 13: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.com

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); value = 16; }}

27)

______ A)

94516

B)

download instant at www.easysemester.com

Page 14: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.com94516

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.

28)

______ A)

console

B)

CRT C)

secondary storage devices

D)

CPU

29)

What would be printed out as a result of the following code?

System.out.println("The quick brown fox" + "jumped over the \n"

"slow moving hen.");

29)

______ A)

The quick brown fox jumped over the \nslow moving hen. download instant at www.easysemester.com

Page 15: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comB)

The quick brown foxjumped over theslow moving hen.

C)

The quick brown fox jumped over theslow 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 /* download instant at www.easysemester.com

Page 16: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comC)

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.

32)

______ A)

\r

B)

\n

C)

\t

D)

\b

33)

If the following Java statements are executed, what will be displayed?

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");

33)

______ A)

The top three winners areJody, the Giant\nBuffy, the BarbarianAdelle, the Alligator

B)

download instant at www.easysemester.com

Page 17: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comThe top three winners areJody, the GiantBuffy, the BarbarianAdelle, the Alligator

C)

The top three winners areJody, the GiantBuffy, 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'; download instant at www.easysemester.com

Page 18: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comC)

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.");

36)

______ A)

I am enjoying this class.I AM ENJOYING THIS CLASS.i am enjoying this class.Character at index x = nmsg has 24 characters.

B)

I am enjoying this class.I AM ENJOYING THIS CLASS.i am enjoying this class.Character at index x = nmsg has 25 characters.

C)

I am enjoying this class.I AM ENJOYING THIS CLASS.i am enjoying this class.Character at index x = emsg has 25 characters.

D)

I am enjoying this class.

download instant at www.easysemester.com

Page 19: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comI AM ENJOYING THIS CLASS.i am enjoying this class.Character at index x = emsg has 24 characters.

37)

Which of the following is valid?

37)

______ A)

float y;double z;z = 934.21;y = z;

B)

float w;w = 1.0f;

C)

double v;v = 1.0f;

D)

float y;y = 54.9;

38)

Every Java application program must have

38)

______ A)

a class named MAIN

B)

integer variables C)

comments

download instant at www.easysemester.com

Page 20: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comD)

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

40)

______ A)

19

B)

3

C)

5.25

D)

7

download instant at www.easysemester.com

Page 21: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.com

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 );

42)

______ A)

x

B)

x = 54.3 C)

x = 108.6

D)

Nothing, this is an error.

43)

download instant at www.easysemester.com

Page 22: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comThis is a variable whose content is read only and cannot be changed during the program's execution of the program.

43)

______ A)

operator

B)

reserved word

C)

named constant

D)

literal

44)

What is the result of the following expression?25 - 7 * 3 + 12/3

44)

______ A)

12

B)

8

C)

10

D)

6

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.

download instant at www.easysemester.com

Page 23: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.com45)

______

46)

Assuming that pay has been declared a double, the following statement is valid.pay = 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)

download instant at www.easysemester.com

Page 24: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comIdentifiers 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)

______

download instant at www.easysemester.com

Page 25: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.com

1)

C

2)

A

3)

C

4)

A

5)

B

6)

A

7)

D

8)

A

9)

C

10)

D

11)

D

12)

B download instant at www.easysemester.com

Page 26: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.com

13)

C

14)

C

15)

D

16)

D

17)

A

18)

B

19)

B

20)

D

21)

C

22)

A

23)

B

24)

download instant at www.easysemester.com

Page 27: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.comB

25)

A

26)

A

27)

D

28)

A

29)

D

30)

C

31)

B

32)

B

33)

C

34)

D

35)

D

download instant at www.easysemester.com

Page 28: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.com36)

B

37)

B

38)

D

39)

A

40)

D

41)

D

42)

D

43)

C

44)

B

45)

TRUE

46)

FALSE

47)

FALSE

download instant at www.easysemester.com

Page 29: Chapter 2 Exam - Easy semestereasysemester.com/sample/Test-Bank-for-Starting-Out-with... · Web view... All Java lines of code end with semicolons. 48) _____ 49) A variable's scope

download instant at www.easysemester.com 48)

FALSE

49)

TRUE

50)

FALSE

51)

FALSE

52)

TRUE

53)

TRUE

54)

TRUE

download instant at www.easysemester.com