Issuu on Google+

Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis Chapter 2 Exam Name___________________________________

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Which of the following is not a valid comment statement?

1

1) _______ A) /** comment 4 B) /* comment 2 */ C) */ comment 3 /* D) // comment 1

When saving a Java source file, save it with an extension of

2

2) _______ A) .java B) .javac C) .src D) .class

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

3


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis 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 = j msg has 20 characters. B) I am enjoying java. I AM ENJOYING JAVA. i am enjoying java. Character at index x = o 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. D) I am enjoying java. I AM ENJOYING JAVA. i am enjoying java. Character at index x = y msg has 19 characters.

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

4

4) _______ A) literal B) operator C) assignment statement D)


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis variable

Which of the following is not a rule that must be followed when naming identifiers?

5

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.

Character literals are enclosed in _____; string literals are enclosed in _____.

6

6) _______ A) single quotes; double quotes B) double quotes; single quotes C) single quotes; single quotes D) double quotes; double quotes

What is the result of the following statement? 17 % 3 * 2 - 12 + 15 7) _______ A) 105

7


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis B) 12 C) 8 D) 7

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); 8) _______ A) 8.0 B) 4 C) 0 D) 8.25

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

9

_______ A) -5 B) -50


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis C) 5 D) 25

Variables are classified according to their _____.

1

10) ______ A) names B) location in the program C) value D) data type

Which of the following will correctly convert the data type, if x is a float and y is a double?

1

11) ______ A) x = float y; B) x = <float>y; C) x = y; D) x = (float)y;


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis The boolean data type may contain values in the following range of values

1

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

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

1

13) ______ A) x = 160, y = 80 B) x = 32, y = 4 C) x = 37, y = 5 D) x = 9, y = 52

This is a named storage location in the computer's memory.

1


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis 14) ______ A) operator B) constant C) variable D) literal

Given the declaration double r;, which of the following statements is invalid?

1

15) ______ A) r = 9.4632E15; B) r = 326.75; C) r = 9.4632e15; D) r = 2.9X106;

To print "Hello, world" on the monitor, use the following Java statement 16) ______ A) SystemOutPrintln("Hello, world"); B) Print("Hello, world"); C)

1


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis System.out.println{"Hello, world"} D) System.out.println("Hello, world");

Variables of the boolean data type are useful for

1

17) ______ A) evaluating true/false conditions B) working with very large integers C) working with small integers D) evaluating scientific notation

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

1

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 5785 hens There are x5\nhens in the hen house.

in the hen house. C)

D) There are 5785 hens in the hen house.


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis In the following Java statement what value is stored in the variable name? String name = "John Doe"; 19)

1

______ A) "name" B) The memory address where "John Doe" is located C) The memory address where name is located D) "John Doe"

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)

2

______ A) x = 22, y = 26 B) x = 22, y = 4 C) x = 22, y = 88 D) Nothing, this is an error

A Java program must have at least one

2

21) ______ A) Comment B)


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis System.out.println(); statement C) Class definition D) Variable

What will be displayed after the following statements have been executed? int x = 15, y = 20, z x += 12; y /= 6; z -= 14; System.out.println("x ", ",

2

= 32;

= " + 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

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

2


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis

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

2

int x = 5, y = 28; float z; z = (float) (y / x); 24) ______ A) 5.60 B) 5.0 C) 5.6 D) 3.0

The primitive data types only allow a(n) _____ to hold a single value.

2

25) ______ A) variable B) class C) literal D) object


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis 2

Which Scanner class method reads a String? 26) ______ nextLine

A) B)

getString() C) readString() D) nextString()

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

2

27) ______ A) 94516 B) 9 45 16

C)

9 45 16 D) Nothing, this is an error


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis 2 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

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. B) The quick brown fox jumped over the slow mov The quick brown fox jumped over the slow mov Nothing. This is an error.

Which of the following is not a primitive data type?

ing hen. C)

ing hen. D)

3


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis 30) ______ A) short B) long C) String D) float

Which of the following does not describe a valid comment in Java?

3

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 */

3 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


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis C) \t D) \b

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

3

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 are Jody Giant\nBuffy, the BarbarianAdelle, the Alligator B) , the The top three winners are Jody, the Giant Buffy, the Barbarian Ade the Alligator C) lle, The top three winners are Jody, the Giant Buff the BarbarianAdelle, the Alligator D) y, The top three winners are Jody, the Giant\nBuffy, the BarbarianAdelle, and the Alligator

If x has been declared an int, which of the following is invalid?

3

34) ______ A) x = 0; B) x = 592; C)


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis x = -58932; D) x = 1,000;

Which of the following is a valid Java statement?

3

35) ______ A) string str = "John Doe"; B) String str = 'John Doe'; C) string str = 'John Doe'; D) String str = "John Doe";

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 = n

3


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis msg has 24 characters. B) I am enjoying this class. I AM ENJOYING THIS CLASS. i am enjoying this class. Character at index x = n msg I am enjoying this class. I AM ENJOYING THIS CLASS. i am enjoying this class. Character at index x = e

has 25 characters. C)

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.

Which of the following is valid?

3

37) ______ A) float y; double z; z = 934.21;

float w;

double v;

y = z; B) w = 1.0f; C) v = 1.0f; D)

float y; y = 54.9;

Every Java application program must have 38) ______

3


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis A) a class named MAIN B) integer variables C) comments D) a method named main

To compile a program named, First, use the following command

3

39) ______ A) javac First.java B) java First.java C) javac First D) compile First.javac

What is the result of the following statement? 25/4 + 4 * 10 % 3 40)

4

______ A) 19 B) 3 C)


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis 5.25 D) 7

Which Scanner class method reads an int? 41) ______ readInt()

A) B)

getInt() C) read Int() D) nextInt()

What will be displayed after the following statements have been executed? final double x; x = 54.3; System.out.println("x = " + x ); 42)

4

______ A) x B) x = 54.3 C) x = 108.6 D)


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis Nothing, this is an error.

4 This 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

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

4

______ A) 12 B) 8 C) 10 D) 6

TRUE/FALSE. Write 'T' if the statement is true and 'F' if the statement is false.


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis 45) Programming style includes techniques for consistently putting spaces and indentation in a program so visual cues are created. 45) ______

Assuming that pay has been declared a double, the following statement is valid. pay = 2,583.44; 46)

4

______

Both character literals and string literals can be assigned to a char variable.

4

47) ______

All Java lines of code end with semicolons.

4

48) ______

A variable's scope is the part of the program that has access to the variable.

4

49) ______

In Java the variable named One is the same as the variable named ONE. 50)

5


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis ______

Identifiers and class names are examples of variables.

5

51) ______

If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.

5

52) ______

5 Named constants are initialized with a value, that value cannot be changed during the execution of the program. 53) ______

A variable's scope is the part of the program that has access to the variable. 54) ______

1) C

2) A

3) C

5


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis 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)


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis D

17) A

18) B

19) B

20) D

21) C

22) A

23) B

24) B

25) A

26) A

27) D

28) A


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis 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


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis 42) D

43) C

44) B

45) TRUE

46) FALSE

47) FALSE

48) FALSE

49) TRUE

50) FALSE

51) FALSE

52) TRUE

53) TRUE

54) TRUE


Full file at http://testbank360.eu/test-bank-starting-out-with-java-4th-edition-tony-gaddis


Test bank starting out with java 4th edition tony gaddis