JAVA练习题含答案-answer to practice 6

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Chapter 6

Arrays

Multiple Choice

1)The individual variables that together make up the array are referred to as:

(a)indexed variables

(b)subscripted variables

(c)elements of the array

(d)all of the above

Answer: D

2)What is the correct expression for accessing the 5th element in an array named colors?

(a)colors[3]

(b)colors[4]

(c)colors[5]

(d)colors[6]

Answer: B

3)Consider the following array:

What is the value of myArray[myArray[1] – myArray[0]]

(a)7

(b)9

(c)-3

(d)6

Answer: C

Copyright © 2006 Pearson Education Addison-Wesley. All rights reserved. 1

2 Walter Savitch •Absolute Java2/e: Chapter 6 Test Bank

4)The subscript of the first indexed variable in an array is:

(a)0

(b)1

(c)2

(d)3

Answer: A

5)The correct syntax for accessing the length of an array named Numbers is:

(a)Numbers.length()

(b)Numbers.length

(c)both A and B

(d)none of the above

Answer: B

6)An ArrayIndexOutOfBounds error is a:

(a)compiler error

(b)syntax error

(c)logic error

(d)all of the above

Answer: C

7)Which of the following initializer lists correctly initializes the indexed variables of an array named

myDoubles?

(a)double myDoubles[double] = {0.0, 1.0, 1.5, 2.0, 2.5};

(b)double myDoubles[5] = new double(0.0, 1.0, 1.5, 2.0, 2.5);

(c)double[] myDoubles = {0.0, 1.0, 1.5, 2.0, 2.5};

(d)array myDoubles[double] = {0.0, 1.0, 1.5, 2.0, 2.5};

Answer: C

8)The base type of an array may be all of the following but:

(a)string

(b)boolean

(c)long

(d)all of these may be a base type of an array.

Answer: D

9)The correct syntax for passing an array as an argument in a method is:

(a)a[]

(b)a()

(c)a

(d)a[0]..a[a.length]

Answer: C

Copyright © 2006 Pearson Education Addison-Wesley. All rights reserved.

Chapter 6 Arrays 3 10)Java provides a looping mechanism for objects of a collection. This looping mechanism is called a

__________ loop.

(a)While

(b)For

(c)For each

(d)All of the above

Answer: C

11) A _________ can occur if a programmer allows an accessor method to return a reference to an array

instance variable.

(a)short circuit

(b)privacy leak

(c)partially filled array

(d)syntax error

Answer: B

12) A ________ loop is a good way to step through the elements of an array and perform some program

action on each indexed variable.

(a)while

(b)do…while

(c)for

(d)all of the above

Answer: C

True/False

1)An array is a collection of variables all of the same type.

Answer:True

2)An array has only one public instance variable, which is named length.

Answer:True

3)An arrays length instance variables value can be changed by a program.

Answer:False

4)An array name references a memory address.

Answer:True

5)You can only use array indexed variables as arguments to methods.

Answer:False

Copyright © 2004 Addison-Wesley. All rights reserved.

相关文档
最新文档