Chapter 7 MC2 Review - Computer Programming
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];
The value variable will contain the sum of all the values in the numbers array.
Which of the following statements is(are) true about this code?final int ARRAY_SIZE = 10;long[] array1 = new long[ARRAY_SIZE];
All of these are true.
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.
What does the following statement do?double[] array1 = new double[10];
It does all of these.
What does specify in the following statement?ArrayList nameList = new ArrayList();
It specifies that only String objects may be stored in the ArrayList object.
What will be the result after the following code is executed?final int ARRAY_SIZE = 5;float[] x = float[ARRAY_SIZE];for (i = 1; i <= ARRAY_SIZE; i++){x[i] = 10.0;}
The code contains a syntax error and will not compile.
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.
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"
Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList?
add
Which of the following is a valid declaration for a ragged array with five rows but no columns?
int[][] ragged = new int[5][];
To return an array of long values from a method, which return type should be used for the method?
long[]
If numbers is a two-dimensional array, which of the following would give the number of columns in row r?
numbers[r].length
Which of the following methods returns a string representing all of the items stored in an ArrayList object?
toString
What is the value of scores[2][3] in the following array?int[][] scores = { {88, 80, 79, 92}.{75, 84, 93, 80},{98, 95, 92, 94},{91, 84, 88, 96} };
94
Given the following two-dimensional array declaration, which statement is true?int[][] numbers = new int[6][9];
The numbers array has 6 rows and 9 columns.