Java - Final Chapter 7
What will be the results after the following code is executed? int [] array1 = new int[25]; // code that will put values in array1 int value = array1[0]; For (int a = 1; a < array1.length; a++) { if (array1[a] > value) value = array1[a]; }
Value contains the highest value in array1
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 < array.length; a++) { Value += array1[a]; }
Value contains the sum of all values in array1
What will be the results after the following code is executed? Int [] x = {55, 33, 88, 22, 99, 44, 66, 77}; Int a = 10; if(x[2] > x[5]) a = 5; else a = 8;
a = 5
An array's subscripts always start with ___
0
If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?
0 through 14
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; }
180
For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};
A reference to the String object containing "ghi"
When an arrays reference variable is passed to a method ___
All of these: The address of (reference to) the array is passed The receiving method has direct access to the original array The receiving method can change values in the original array
What will be the result after the following code is executed? Final int ARRAY_SIZE = 5; Float [] x = float[ARRAY_SIZE]; for {int i = 1; i < ARRAY_SIZE; i++} { X[i] = 10.0; }
All the values in the array except the first will be initialized to 10.0
What would be the result of executing the following code? Int[] x = {0, 1, 2, 3, 4, 5};
An array of 6 values ranging from 0 through 5 and referenced by the variable x will be created
The ___ indicates the number of elements the array can hold
Array's size
In memory, an array of String objects ___
Consists of an array of references to String objects
Each array in java has a public field named ___ that contains the number of elements in the array
Length
Given that String[] str has been initialized, to get a copy of str[0] with all the characters converted to uppercase, you would use the ___ statement
str[0].toUpperCase();
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]; }
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}; x = y; y = x;
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
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
Array bounds checking
A __ is used as an index to pinpoint a specific element within an array
Subscript
When an individual element of an array is passed to a method ___
The receiving method has direct access to the original 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]; }
The value variable will contain the lowest value in the numbers array