Java Chapter 7
a reference to the String object containing "ghi"
For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};
a = 5
What will be the results after the following code is executed? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) { a = 5; } else { a = 8; }
180
What will be the value of x[8] after the following code is executed? final int SUB = 12; int[] x = new int[SUB]; int y = 100; for(int i = 0; i < SUB; i++) { x[i] = y; y += 10; }
The value variable will contain the lowest value in the numbers array.
What would be the result after the following code is executed? int[] numbers = {40, 3, 5, 7, 8, 12, 10}; int value = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] < value) { value = numbers[i]; } }
This code would cause the program to crash.
What would be the result after the following code is executed? final int SIZE = 25; int[] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = 0; for (int a = 0; a <= array1.length; a++) { value += array1[a]; }
The value variable will contain the sum of all values except the first one in the in the numbers array.
What would be the result after the following code is executed? int[] numbers = {50, 10, 15, 20, 25, 100, 30}; int value = 0; for (int i = 1; i < numbers.length; i++) value += numbers[i];
is used to locate a specific item in a collection of data
A search algorithm ________.
subscript
A(n) ________ is used as an index to pinpoint a specific element within an array.
length
Each array in Java has a public field named ________ that contains the number of elements in the array.
array bounds checking
Java performs ________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
What would be the result after the following code is executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; for(int a = 0; a < x.length; a++) { x[a] = y[a]; y[a] = x[a]; }
An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created.
What would be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5};
All of these are true
When an array is passed to a method ________. Multiple Choice: 1) a reference to the array is passed 2) All of these are true 3) the method has direct access to the original array 4) it is passed just as any other object would be passed
the method does not have access to the original array
When an individual element of an array is passed to a method ________.