• Home
  • Textbooks
  • Java Programming
  • Arrays

Java Programming

Joyce Farrell

Chapter 8

Arrays - all with Video Answers

Educators


Section 1

Review Questions

00:43

Problem 1

An array is a list of data items that all _________________.
a. have the same type
b. have different names
c. are integers
d. are null

Aditya Sood
Aditya Sood
Numerade Educator

Problem 2

When you declare an array, _________________.
a. you always reserve memory for it in the same statement
b. you might reserve memory for it in the same statement
c. you cannot reserve memory for it in the same statement
d. the ability to reserve memory for it in the same statement depends on the type of the array

Check back soon!
00:34

Problem 3

For how many integers does the following statement reserve room?
int[] values = new int[34];
a. 0
b. 33
c. 34
d. 35

Aditya Sood
Aditya Sood
Numerade Educator
00:43

Problem 4

Which of the following can be used as an array subscript?
a. char
b. String
c. double
d. int

Aditya Sood
Aditya Sood
Numerade Educator

Problem 5

If you declare an array as follows, how do you indicate the final element of the array?
int[] nums = new int[6];
a. nums[0]
b. nums[5]
c. nums[6]
d. impossible to tell

Check back soon!

Problem 6

If you declare an integer array as follows, what is the value of nums[2]?
int[] nums = {101, 202, 303, 404, 505, 606};
a. 101
b. 202
c. 303
d. impossible to tell

Check back soon!

Problem 7

When you initialize an array by giving it values upon creation, you _________________.
a. do not explicitly give the array a size
b. also must give the array a size explicitly
c. must make all the values zero, blank, or false
d. must make certain each value is different from the others

Check back soon!
01:51

Problem 8

In Java, you can declare an array of 12 elements and initialize _________________.
a. only the first one
b. all of them
c. either one or all of them
d. only the first and last ones

Ernest Castorena
Ernest Castorena
Numerade Educator
03:23

Problem 9

Assume x is an integer and an array is declared as follows. Which of the following statements correctly assigns the value 100 to each of the array elements?
int [] nums $=$ new int [4];
a. $\operatorname{for}(\mathrm{x}=0 ; \mathrm{x}<3 ;++\mathrm{x})$
nums $[\mathrm{x}]=100$;
b. $\operatorname{for}(x=0 ; x<4 ;++x)$
$\operatorname{nums}[\mathrm{x}]=100$;
c. for $(\mathrm{x}=1 ; \mathrm{x}<4 ;++\mathrm{x})$ nums $[\mathrm{x}]=100$;
d. $\operatorname{for}(x=1 ; x<5 ;++x)$ nums $[\mathrm{x}]=100$;

Ernest Castorena
Ernest Castorena
Numerade Educator
00:34

Problem 10

Suppose you have declared an array as follows:
int[] creditScores = {670, 720, 815};
What is the value of creditScores.length?
a. 0
b. 1
c. 2
d. 3

Aditya Sood
Aditya Sood
Numerade Educator

Problem 11

A parallel array is one that _________________.
a. holds values that correspond to those in another array
b. holds an even number of values
c. is placed adjacent to another array in code
d. is placed adjacent to another array in memory

Check back soon!
00:34

Problem 12

When you pass an array element to a method, the method receives _________________.
a. a copy of the array
b. the address of the array
c. a copy of the value in the element
d. the address of the element

Aditya Sood
Aditya Sood
Numerade Educator
00:28

Problem 13

A single array element of a primitive type is passed to a method by _________________.
a. value
b. reference
c. address
d. osmosis

Aditya Sood
Aditya Sood
Numerade Educator
00:34

Problem 14

When you pass an array to a method, the method receives _________________.
a. a copy of the array
b. a copy of the first element in the array
c. the address of the array
d. nothing

Aditya Sood
Aditya Sood
Numerade Educator

Problem 15

When you place objects in order beginning with the object with the highest value, you are sorting in _________________ order.
a. descending
b. ascending
c. demeaning
d. arithmetic

Check back soon!

Problem 16

Using a bubble sort involves comparing each array element with _________________.
a. the corresponding element in a parallel array
b. the adjacent element
c. the arithmetic average
d. the lowest element value

Check back soon!

Problem 17

The following defines a _________________ array:
int[][] nums = { {1, 2}, {3, 4}, {5, 6} };
a. one-dimensional
b. two-dimensional
c. three-dimensional
d. six-dimensional

Check back soon!
05:10

Problem 18

How many rows are contained in the following array?
$$
\begin{aligned}
& \text { double [] [] prices }=\{\{2.56,3.57,4.58,5.59\} \text {, } \\
&\{12.35,13.35,14.35,15.00\}\} ;
\end{aligned}
$$
a. 1
b. 2
c. 4
d. 8

Ernest Castorena
Ernest Castorena
Numerade Educator
02:48

Problem 19

In the following array, what is the value of codes[2][1]?
$\begin{aligned} & \text { char [] [] codes }=\left\{\text { ' }^{\prime} \text { ', 'D ', 'M '\}, }\right. \\ & \text { \{'P ', 'R ', 'S '\}, } \\ & \{' U \text { ', 'V ', 'Z '\}\}; } \\ & \end{aligned}$
a. 'P'
b. 'R'
c. 'U'
d. 'V'

Dennis Howard
Dennis Howard
Numerade Educator

Problem 20

The methods in the Arrays class _________________.
a. are static methods
b. are always used after instantiating an Arrays object
c. must be modified by a programmer before they are useful
d. can be used without importing any package

Check back soon!