Question: QUESTION 16 Remember that the % operator evaluates to the remainder after integer division e.g. 8 % 4 is 0, 11 % 4 is 3.
QUESTION 16
Remember that the % operator evaluates to the remainder after integer division e.g. 8 % 4 is 0, 11 % 4 is 3. What is the value of x after the following?
int x = 0; for (int i = 1; i < 6; ++i) if (i % 2 == 0) x = x + i;
| A. | 0 | |
| B. | 15 | |
| C. | 6 | |
| D. | 21 |
QUESTION 17
Assume that mynums is an array of 5 integers. What will be the contents of mynums after the following code fragment?
for (int i = 0; i < 5; i++) mynums[i] = i + 1;
| A. | 1 2 3 4 5 | |
| B. | 0 1 2 3 4 | |
| C. | 1 2 3 4 | |
| D. | 1 1 1 1 1 |
QUESTION 18
What is the effect of the following code fragment?
for (double element : values)
element = 0;
| A. | The elements of the array named values are initialized to zero | |
| B. | The elements of the array named element are initialized to zero | |
| C. | The first element of the array named values is initialized to zero | |
| D. | The elements of the array named values are not modified |
QUESTION 19
The following statement accesses the element at index 4 in an array:
x = a[4];
What is the equivalent operation using an array list?
| A. | x = a.get(4); | |
| B. | x = a.get(); | |
| C. | x = a.get[4]; | |
| D. | x = a[4]; |
QUESTION 20
Assume that values is an array of random integers. Which condition must be used in the indicated area so the code fragment below will set max to the largest value in values?
int max = values[0];
for (int val: values)
{
if (/* put condition here */)
max = val;
}
| A. | max > val | |
| B. | val > max | |
| C. | values[val] > max | |
| D. | max > values[val] |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
