Podcast
Questions and Answers
In practice 6.09, what does the code segment count in the 'values' array?
In practice 6.09, what does the code segment count in the 'values' array?
- The number of even elements (correct)
- The average of all elements
- The number of odd elements
- The sum of all elements
What is missing in the code in practice 6.10 to correctly manipulate array elements?
What is missing in the code in practice 6.10 to correctly manipulate array elements?
- values[k] = Math.pow(values[k], 2); (correct)
- values[k] = sqrt(values[k]);
- values[k] = values[k]^2;
- values[k] = values[k] * values[k];
How would you correctly call the 'display' method with the 'values' array in practice 6.11?
How would you correctly call the 'display' method with the 'values' array in practice 6.11?
- display(int[] values);
- display(int[] array=values);
- display(values); (correct)
- display(array=values);
How can you complete the 'firstPlusLast' method in practice 6.13 to return the sum of the first and last elements of an array?
How can you complete the 'firstPlusLast' method in practice 6.13 to return the sum of the first and last elements of an array?
Which of the following is the correct way to create an array with 20 double elements?
Which of the following is the correct way to create an array with 20 double elements?
Given the declaration int[] array = {4, 3, 5, 2, 0};, what is the value of array[2]?
Given the declaration int[] array = {4, 3, 5, 2, 0};, what is the value of array[2]?
Which of the following statements would cause a run-time error with the declaration int[] array = {4, 3, 5, 2, 0};?
Which of the following statements would cause a run-time error with the declaration int[] array = {4, 3, 5, 2, 0};?
What output is generated by the code segment below?
int[] values = new int[5];
for (int k = 0; k < values.length; k++) { values[k] = k * 2; }
System.out.println(values);
What output is generated by the code segment below? int[] values = new int[5]; for (int k = 0; k < values.length; k++) { values[k] = k * 2; } System.out.println(values);
Insert the missing statement in the code fragment to initialize the array elements with the values 1, 2, 3,..., 100.
int[] numbers = new int[100];
for (int k = 0; k < numbers.length; k++) { }
Insert the missing statement in the code fragment to initialize the array elements with the values 1, 2, 3,..., 100. int[] numbers = new int[100]; for (int k = 0; k < numbers.length; k++) { }
What output is generated by the code fragment below?
int[] values = {1, 3, 1, 3, 1};
int[] numbers = values;
for (int k = 0; k < values.length; k++) { values[k] = k * 2; }
System.out.print(values);
System.out.print(" " + numbers);
What output is generated by the code fragment below? int[] values = {1, 3, 1, 3, 1}; int[] numbers = values; for (int k = 0; k < values.length; k++) { values[k] = k * 2; } System.out.print(values); System.out.print(" " + numbers);