Question: Question 10.05 pts All the elements of an array in Java MUST conform to the same data type. True False Flag this Question Question 20.05
Question 10.05 pts
All the elements of an array in Java MUST conform to the same data type.
| True |
| False |
Flag this Question
Question 20.05 pts
What is the value stored in the variable z by the statements below? int[ ] q = {3, 2, -2, 4, 7, 0, 1}; int z = q.length;
| 1 |
| 3 |
| 6 |
| 7 |
| None of the above |
Flag this Question
Question 30.05 pts
Which of the following statements declares a new array variable with no syntax errors?
| int[ ] myArr; |
| int[ ][ ] myArr; |
| int[ ] myArr = new int[ 12 ]; |
| int[ ] myArr = { 3, 4, 5, 6 }; |
| All of the above |
Flag this Question
Question 40.05 pts
What is printed by the following code? int[ ] x = {3, 4, 5, 6, 7}; int[ ] y = x; for (int i = 0; i < 3; i++)
y[i + 2] = 3 * y[i];
System.out.println( x[3] );
| 5 |
| 6 |
| 9 |
| 12 |
| 15 |
Flag this Question
Question 50.05 pts
In the following method call, which argument is an array? myObject.some_method(x, y, 3);
| x is an array |
| y is an array |
| both x and y are arrays |
| neither x nor y is an array |
| can't say without seeing more code |
Flag this Question
Question 60.05 pts
Which of the following statements correctly uses a reference to the entire array myArray as the argument of the method call? (The method call comes from within the same class, so no qualifier is needed.) public void myMethod( int[ ] a ) { ... }
| myMethod( myArray ); |
| myMethod( myArray[ ] ); |
| myMethod( myArray[ 0 ] ); |
| All of the above |
Flag this Question
Question 70.05 pts
An array of doubles is stored in the variable v as shown below. Which statement below will print some or all of the contents of the array with NO errors (syntax or logical)? int vSize = 5; double[ ] v = new double[vSize]; for (int i = 0; i < vSize; i++)
v[i] = 1.1;
| System.out.println( v ); |
| System.out.println( v[0] ); |
| System.out.println( v[vSize] ); |
| All of the above |
| None of the above |
Flag this Question
Question 80.05 pts
Which of the following method signatures correctly specifies an array as a return type?
| private array testMethod ( int x ) |
| private int[ ] testMethod ( int x ) |
| private double[5] testMethod ( int x ) |
| private double testMethod[ ] ( int x ) |
| can't tell from this code |
Flag this Question
Question 90.05 pts
Which of the following is the BEST description of a 2-D array in Java?
| a 2-D array is a table |
| a 2-D array is an array of arrays |
| a 2-D array is a matrix |
| a 2-D array is a nested loop |
| a 2-D array is an ArrayList |
Flag this Question
Question 100.05 pts
A loop is being used to find the lowest value in a double array named numbers. Which of the following statements performs a useful initialization of the accumulator?
| double lowestValue = 0; |
| double lowestValue = numbers; |
| double lowestValue = numbers[0]; |
| double lowestValue; // no initialization needed |
| Any of the above. |
Flag this Question
Question 110.05 pts
The following bit of code is attempting to find the sum of all the elements in the array 'codes'. One line contains a logic error. Which line is it? long[] codes = ...; // Assume the array has been filled with values ... long sum = 0; // line 1 for ( int i = 1; i < codes.length; i++ ) { // line 2
sum = sum + codes[i]; // line 3
}
| line 1 |
| line 2 |
| line 3 |
Question 120.05 pts
Which of the following is true about a sifting operation?
| The operation may produce more than one result. |
| The operation may produce no results. |
| The search must continue even after a match is found; the entire collection must be examined. |
| All of the above. |
| None of the above. |
Flag this Question
Question 130.05 pts
The following bit of code is attempting to find the average number of characters in all of the Strings in a String array. One line has a syntax error. Which line is it? String[] names = ... // Assume the array has been filled with values ... double averageLength = 0; // line 1 int i; for (i = 0; i < names.length(); i++ ) { // line 2
averageLength += names[i].length(); // line 3
} averageLength = averageLength / i; // line 4
| line 1 |
| line 2 |
| line 3 |
| line 4 |
Flag this Question
Question 140.05 pts
The following bit of code is attempting to find the x-coordinate of the Point that is farthest to the right in the x-y plane in the array 'points'. One line contains an error. Which line is it? Point[] points = ... // Assume the array has been filled with Point object references ... double xMax = points[0].getX(); // line 1 for ( int i = 1; i < points.length; i++ ) { // line 2
if ( points[i].getX() > xMax ) { // line 3
xMax = points[i]; // line 4
}
}
| line 2 |
| line 3 |
| line 4 |
Flag this Question
Question 150.05 pts
The last 3 lines in the following program are supposed to swap the two elements in the array 'blooms' identified by the index values 'mary' and 'john'. Choose from among the answers listed the correct statement for the middle of these 3 lines: Flower[] blooms = ... // Assume this array is filled with object references int mary, john; // Assume these variables have values assigned to them ... Flower temp = blooms[mary]; // What statement goes here?? blooms[john] = temp;
| john = mary; |
| temp = blooms[john]; |
| blooms[mary] = blooms[john]; |
| blooms[john] = blooms[mary]; |
| None of the above -- no statement is needed. |
Flag this Question
Question 160.05 pts
The following statement constructs a new String array. What initial value is stored in each of the array elements? String[] words = new String[8];
| the empty String ( "" ) |
| the numbers 1 through 8 |
| the numbers 0 through 7 |
| the value null |
| the value void |
Flag this Question
Question 170.05 pts
What is printed out by the following short program? double[] x1 = {3.3, 4.4, 5.5, 6.6}; double[] x2 = x1; x2[1] = 24.0; double x = x1[1] * 2; System.out.println(x1[1]);
| 3.3 |
| 4.4 |
| 6.6 |
| 8.8 |
| 24.0 |
Flag this Question
Question 180.05 pts
Consider this code: String[] names = {"Mary", "Jose", "Minh"}; System.out.println(names[1]); What is the data type of names[1]?
| String |
| String[] |
| array |
| char |
Flag this Question
Question 190.05 pts
[This is different than the previous question.] Consider this code: String[] names = {"Mary", "Jose", "Minh"}; System.out.println(names[1]); What is the data type of names?
| String |
| String[] |
| array |
| char |
Flag this Question
Question 200.05 pts
What will be printed by the following program? int[] nums1 = {7, 6, 5, 4}; int[] nums2 = {7, 6, 5, 4}; boolean ans1 = (nums1 == nums2); boolean ans2 = nums1.equals(nums2); boolean ans3 = Arrays.equals(nums1, nums2); System.out.println( ans1 + "-" + ans2 + "-" + ans3 );
| true - true - true |
| false - true - true |
| false - false - true |
| false - false - false |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
