Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Which of these refers to the first element of an array named cells? Select one:

ID: 3756204 • Letter: W

Question

Which of these refers to the first element of an array named cells?

Select one:

a. cells(1)

b. cells

c. cells[1]

d. cells.first()

e. cells[0]

Which of these should not be done for an array instance variable?

Select one:

a. Making a copy of it.

b. Resizing it.

c. Returning a reference to it from a method.

d. Sorting it.

e. Searching it.

Which of these generally takes the least time?

Select one:

a. array resizing

b. array binary search

c. array sequential copy

d. array sorting

e. array sequential search

Which of these refers to the last element of an array named accounts?

Select one:

a. accounts.last()

b. accounts[accounts.length]

c. accounts[length]

d. accounts[accounts.length()]

e. accounts[accounts.length - 1]

Which of these instantiates an array of ints with 100 elements?
(Assume primes has been declared as an array of ints.)

Select one:

a. primes = new int[100]

b. primes = new int[101]

c. primes int[100]

d. primes = new int[]

e. primes = new int[99]

Explanation / Answer

The array indexing starts with 0 to n where n is the number of elements.

a. Here the index of the first element of the array is 0, hence the answer is cells[0]

b. Resizing the array is not generally recomended as the time and space complexity of this operation is O(n).

c. Binary search takes the shortest time O(Log(n)).

d. The length of an array can be calculated by the .length operator, so accounts.length will give the total length of the array. But since our array indexing stat with 0 the last index is accounts.length-1, hence the answer is accounts[accounts.length - 1].

e. fir declaring the array we give the size of the array in square bracket hence the answer is primes int[100]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote