CS 4A: Chapter 7 - 1D Arrays

¡Supera tus tareas y exámenes ahora con Quizwiz!

An array can be used as:

- a local variable - a return value - a parameter

How can you initialize an array of two characters to 'a' and 'b'?

- char[] charArray = {'a', 'b'}; - char[] charArray = new char[]{'a', 'b'};

Which of the following declarations are correct?

- int[] list = {1, 2, 3, 4}; - int[] list = new int[]{1, 2, 3, 4};

Which of the following is the correct header of the main method?

- public static void main(String[] args) - public static void main(String args[]) - public static void main(String[] x) - public static void main(String x[])

Assume int[] scores = {1, 20, 30, 40, 50}, what value does java.util.Arrays.binarySearch(scores, 3) return?

-2

Suppose int[] numbers = new int[10], what is numbers[0]?

0

Assume int[] scores = {1, 20, 30, 40, 50}, what value does java.util.Arrays.binarySearch(scores, 30) return?

2

Use the selectionSort method presented in this section to answer this question. Assume list is {3.1, 3.1, 2.5, 6.4, 2.1}, what is the content of list after the first iteration of the outer loop in the method?

2.1, 3.1, 2.5, 6.4, 3.1

If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is ________.

3

Assume int[] t = {1, 2, 3, 4}. What is t.length?

4

How many elements are in array double[] list = new double[5]?

5

An array variable can be declared and redeclared in the same block. True/False

False

Binary search can be applied on an unsorted list. True/False

False

The array size is specified when the array is declared. True/False

False

The element in the array must be of a primitive data type. True/False

False

What is the correct term for numbers[99]?

Indexed variable

Which correctly creates an array of five empty Strings?

String[] a = {"", "", "", "", ""};

Analyze the following code. int[] list = new int[5]; list = new int[6];

The code can compile and run fine. The second line assigns a new array to list.

When you pass an array to a method, the method receives ________.

The reference of the array

When you return an array from a method, the method returns ________.

The reference of the array

The array index of the first element in an array is 0. True/False

True

The arraycopy method does not allocate memory space for the target array. The target array must already be created with memory space allocated. True/False

True

You can use the operator == to check whether two variables refer to the same array. True/False

True

How can you get the word "abc" in the main method from the following call? java Test "+" 3 "abc" 2

args[2]

________ declares an array of char.

char[] chars

Which of the following is correct to create an array?

int[] m = {1, 2, 3};

The ________ method sorts the array scores of the double[] type.

java.util.Arrays.sort(scores)

The reverse method is defined in this section. What is list1 after executing the following statements? int[] list1 = {1, 2, 3, 4, 5, 6}; int[] list2 = reverse(list1);

list1 is 1 2 3 4 5 6

Use the selectionSort method presented in this section to answer this question. What is list1 after executing the following statements? double[] list1 = {3.1, 3.1, 2.5, 6.4}; selectionSort(list1);

list1 is 2.5 3.1, 3.1, 6.4

Suppose a method p has the following heading: public static int[] p() What return statement may be used in p()?

return new int[]{1, 2, 3};

Assume the signature of the method xMethod is as follows. public static void xMethod(double[] a) Which of the following could be used to invoke xMethod?

xMethod(new double[2]);


Conjuntos de estudio relacionados

Psychology Chapter 3 study guide

View Set

Adult Health Musculoskeletal Quiz

View Set

Ch 12 Spirituality & Religious Practices

View Set

CHAPTER 23 Nursing Care of newborn

View Set