Ch. 7 Quiz

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ________. > 3.4 > 2.0 > 3.5 > 5.5 > undefined

2.0

If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is __________. > 0 > 1 > 2 > 3 > 4

3

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

4

How many elements are in array double[] list = new double[5]? > 4 > 5 > 6 > 0

5

In the following code, what is the output for list1? public class Test { public static void main(String[] args) { int[] list1 = {1, 2, 3}; int[] list2 = {1, 2, 3}; list2 = list1; list1[0] = 0; list1[1] = 1; list2[2] = 2; for (int i = 0; i < list1.length; i++) System.out.print(list1[i] + " "); } } > 1 2 3 > 1 1 1 > 0 1 2 > 0 1 3

0 1 2

In the following code, what is the output for list2? public class Test { public static void main(String[] args) { int[] list1 = {1, 2, 3}; int[] list2 = {1, 2, 3}; list2 = list1; list1[0] = 0; list1[1] = 1; list2[2] = 2; for (int i = 0; i < list2.length; i++) System.out.print(list2[i] + " "); } } > 1 2 3 > 1 1 1 > 0 1 2 > 0 1 3

0 1 2

What is the output of the following code? double[] myList = {1, 5, 5, 5, 5, 1}; double max = myList[0]; int indexOfMax = 0; for (int i = 1; i < myList.length; i++) { if (myList[i] > max) { max = myList[i]; indexOfMax = i; } } System.out.println(indexOfMax); > 0 > 1 > 2 > 3 > 4

1

What is output of the following code: public class Test { public static void main(String[] args) { int list[] = {1, 2, 3, 4, 5, 6}; for (int i = 1; i < list.length; i++) list[i] = list[i - 1]; for (int i = 0; i < list.length; i++) System.out.print(list[i] + " "); } } > 1 2 3 4 5 6 > 2 3 4 5 6 6 > 2 3 4 5 6 1 > 1 1 1 1 1 1

1 1 1 1 1 1

What is the output of the following code? int[] myList = {1, 2, 3, 4, 5, 6}; for (int i = myList.length - 2; i >= 0; i--) { myList[i + 1] = myList[i]; } for (int e: myList) System.out.print(e + " "); > 1 2 3 4 5 6 > 6 1 2 3 4 5 > 6 2 3 4 5 1 > 1 1 2 3 4 5 > 2 3 4 5 6 1

1 1 2 3 4 5

What is output of the following code: public class Test { public static void main(String[] args) { int[] x = {120, 200, 016}; for (int i = 0; i < x.length; i++) System.out.print(x[i] + " "); } } > 120 200 16 > 120 200 14 > 120 200 20 > 016 is a compile error. It should be written as 16.

120 200 14

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

2

The __________ method copies the sourceArray to the targetArray. > System.copyArrays(sourceArray, 0, targetArray, 0, sourceArray.length); > System.copyarrays(sourceArray, 0, targetArray, 0, sourceArray.length); > System.arrayCopy(sourceArray, 0, targetArray, 0, sourceArray.length); > System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);

System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);

Analyze the following code: public class Test { public static void main(String[] args) { int[] x = {1, 2, 3, 4}; int[] y = x; x = new int[2]; for (int i = 0; i < y.length; i++) System.out.print(y[i] + " "); } } > The program displays 1 2 3 4 > The program displays 0 0 > The program displays 0 0 3 4 > The program displays 0 0 0 0

The program displays 1 2 3 4

Analyze the following code: public class Test { public static void main(String[] args) { double[] x = {2.5, 3, 4}; for (double value: x) System.out.print(value + " "); } } > The program displays 2.5, 3, 4 > The program displays 2.5 3 4 > The program displays 2.5 3.0 4.0 > The program displays 2.5, 3.0 4.0 > The program has a syntax error because value is undefined.

The program displays 2.5 3.0 4.0

Analyze the following code: public class Test { public static void main(String[] args) { int[] a = new int[4]; a[1] = 1; a = new int[2]; System.out.println("a[1] is " + a[1]); } } > The program has a compile error because new int[2] is assigned to a. > The program has a runtime error because a[1] is not initialized. > The program displays a[1] is 0. > The program displays a[1] is 1.

The program displays a[1] is 0.

The JVM stores the array in an area of memory, called _______, which is used for dynamic memory allocation where blocks of memory are allocated and freed in an arbitrary order. > stack > heap > memory block > dynamic memory

heap

What is the correct term for numbers[99]? > index > index variable > indexed variable > array variable > array

indexed variable

The __________ method sorts the array scores of the double[] type. > java.util.Arrays(scores) > java.util.Arrays.sorts(scores) > java.util.Arrays.sort(scores) > Njava.util.Arrays.sortArray(scores)

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 > list1 is 6 5 4 3 2 1 > list1 is 0 0 0 0 0 0 > list1 is 6 6 6 6 6 6

list1 is 1 2 3 4 5 6

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

list1 is 6 5 4 3 2 1

Suppose a method p has the following heading: public static int[] p() What return statement may be used in p()? > return 1; > return {1, 2, 3}; > return int[]{1, 2, 3}; > return new int[]{1, 2, 3};

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

When you pass an array to a method, the method receives __________. > a copy of the array > a copy of the first element > the reference of the array > the length of the array

the reference of the array

When you return an array from a method, the method returns __________. > a copy of the array > a copy of the first element > the reference of the array > the length of the array

the reference of the array

Assume int[] scores = {1, 20, 30, 40, 50}, what is the output of System.out.println(java.util.Arrays.toString(scores))? > {1, 20, 30, 40, 50} > [1, 20, 30, 40, 50] > {1 20 30 40 50} > [1 20 30 40 50]

[1, 20, 30, 40, 50]

What is the representation of the third element in an array called a? > a[2] > a(2) > a[3] > a(3)

a[2]


Ensembles d'études connexes

Health Information Management Technology, Chapter 7

View Set

PATH 370 - In Class Quiz 4 (ch. 27, 28, 29, 31, 33)

View Set

Exam 3 Psych Lifespan - Ch. 11 - 14

View Set

Untimed Questions 5: Conditioning and Learning

View Set

History of the Recording Industry FINAL

View Set

Introduction to Nursing--Unit 4 Exam Healthcare Delivery Financing

View Set

Chapter 4: Tort Law - Negligence

View Set