Question 1
1.
How many rows are in the
array that follows?Rental[][] transactions = new Rental[7][3];
Answer
|
7
|
|
|
6
|
|
|
3
|
|
|
2
|
1 points
Question 2
1.
The length of the array
that follows isint[] grades = new int[4];
Answer
|
0
|
|
|
3
|
|
|
4
|
|
|
5
|
1 points
Question 3
1.
What happens when the
code that follows is executed?int[] nums = new int[4];for
(int i = 0; i <= nums.length; i++){ nums[i] =
i;}System.out.println(nums[2]);
Answer
|
It prints “1” to the console.
|
|
|
It prints “2” to the console.
|
|
|
It prints “3” to the console.
|
|
|
It throws an
ArrayIndexOutOfBoundsException.
|
1 points
Question 4
1.
What is printed to the
console when the code that follows is executed?int[] values = {2, 1, 6, 5,
3};Arrays.sort(values);int index = Arrays.binarySearch(values,
5);System.out.println(values[index] - 1);
Answer
|
“2”
|
|
|
“3”
|
|
|
“4”
|
|
|
“5”
|
|
|
“6”
|
1 points
Question 5
1.
What is printed to the
console when the code that follows is executed?int[] years = new
int[5];years[1] = 1992;for (int i = 0; i < years.length;
i++){ years[i]++;}System.out.println(years[3]);
Answer
|
“3”
|
|
|
“4”
|
|
|
“1”
|
|
|
“1994”
|
1 points
Question 6
1.
What is the highest
index value associated with the array that follows?byte[] values = new byte[x];
Answer
|
0
|
|
|
x
|
|
|
x + 1
|
|
|
x – 1
|
|
|
can’t tell from information
given
|
1 points
Question 7
1.
What is the value of
kilos[1] after the code that follows is executed?double[] kilos = {200, 100, 48,
59, 72};for (int i = 0; i < kilos.length; i++){ kilos[i]
*= 2.2;}
Answer
|
200.0
|
|
|
100.0
|
|
|
440.0
|
|
|
220.0
|
1 points
Question 8
1.
What is the value of
names[4] in the following array?String[] names =
{"Jeff", "Dan", "Sally", "Jill",
"Allie"};
Answer
|
Sally
|
|
|
Jill
|
|
|
Allie
|
|
|
name[4] doesn’t exist
|
1 points
Question 9
1.
What is the value of
nums[2] after the following statements are executed?int[] values = {2, 3, 5, 7,
9};int[] nums = values;values[2] = 1;
Answer
|
3
|
|
|
1
|
|
|
5
|
|
|
0
|
1 points
Question 10
1.
What is the value of
temps[2][1] after the code that follows is executed?double[][] temps = new
double[10][5];for (int i = 0; i < temps.length; i++){ for
(int j = 0; j < temps[i].length; j++)
{ temps[i][j] = j +
i; }}
Answer
|
1.0
|
|
|
2.0
|
|
|
3.0
|
|
|
4.0
|
1 points
Question 11
1.
What is the value of the
string named lowest when the code that follows is executed?String[] types =
{"lux", "eco", "comp",
"mid"};Arrays.sort(types);String lowest = types[0];
Answer
|
lux
|
|
|
eco
|
|
|
comp
|
|
|
mid
|
1 points
Question 12
1.
What is the value of the
third element in the array that follows?double[] percents = new
double[4];percents[1] = 85.66;percents[2] = 56.98;percents[3] = 25.66;
Answer
|
25.66
|
|
|
56.98
|
|
|
85.66
|
|
|
a third element doesn’t exist
|
1 points
Question 13
1.
What is the value of the
variable named len after the code that follows is executed?int[][] nums = { {1, 2, 3}, {3,
4, 5, 6, 8}, {1}, {8, 8} };int len = nums[2].length;
Answer
|
1
|
|
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
1 points
Question 14
1.
What is the value of the
variable named len after the code that follows is executed?int[][] nums = { {1, 2, 3}, {3,
4, 5, 6, 8}, {1}, {8, 8} };int len = nums.length;
Answer
|
1
|
|
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
1 points
Question 15
1.
What is the value of the
variable named lists after the statements that follow are executed?String[][] names = new
String[200][10];int lists = names.length;
Answer
|
9
|
|
|
10
|
|
|
199
|
|
|
200
|
|
|
code doesn’t compile
|
1 points
Question 16
1.
What is the value of
times[2][1] in the array that follows?double[][] times = { {23.0,
3.5}, {22.4, 3.6}, {21.3, 3.7} };
Answer
|
3.7
|
|
|
22.4
|
|
|
3.5
|
|
|
21.3
|
|
|
3.6
|
1 points
Question 17
1.
What numbers does the
code that follows print to the console?int[] numbers = {1, 2, 3, 4, 5,
6, 7, 8, 9};for (int i = 0; i < 9; i++){
System.out.println(numbers[i]);}
Answer
|
0-9
|
|
|
1-9
|
|
|
1-8
|
|
|
0-8
|
|
|
0-9
|
1 points
Question 18
1.
Which of the following
is an invalid list of elements in an array?
Answer
|
"Joe", "Doug", "Anne"
|
|
|
"Joe", 3, 25.5
|
|
|
3, 17, 12
|
|
|
12.3, 32.6, 21.7
ans- "Joe",3,25.5
|
1 points
Question 19
1.
Why won’t the following
code execute?double values[] = new double[5];values[5] = 6;
Answer
|
The brackets in the first
statement are misplaced.
|
|
|
An int value can’t be
assigned to a double.
|
|
|
The index is out of bounds.
ans - The index is out of bounds
|
1 points
Question 20
1.
The elements of an
array are stored in ___ location(s) in memory.
Answer
|
contiguous
|
|
|
random
|
|
|
overlapping
|
|
|
the
same
|
1 points
No comments:
Post a Comment