Question 100.05 pts A loop is being used to find the lowest value in a double ar
ID: 3919846 • Letter: Q
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?
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
}
Flag this Question
Question 120.05 pts
Which of the following is true about a siftingoperation?
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
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
}
}
Explanation / Answer
Question 100
Answer
double lowestValue = numbers[0];
Explanation
By giving the first number in numbers, we can compare with the rest of the numbers
Question 110
Answer
line 2
Explanation
i should start from 0 because the indices start from 0
for ( int i = 0; i < codes.length; i++ )
Question 130
Answer
line 2
Explanation
names.length should be there instead of names.length()
Question 140
Answer
line 4
Explanation
xMax = points[i].getX(); should be there instead of xMax = points[i];
Note: 4 sub parts are answered as part of a question -- Policy of Chegg
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.