Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

16. Under which of the following conditions will evaluating this boolean express

ID: 3801384 • Letter: 1

Question

16. Under which of the following conditions will evaluating this boolean expression

cause an ArrayIndexOutOfBoundsException n represents the length of a?

((i <= n) && (a[i] == 0)) || (((i >= n) && (a[i-1] == 0)))

I. i > n
II. i = n
III. i < n

Question 16 options:

17. Suppose the following array is declared: int[ ] grades = {88, 92, 95, 83};

What are the values in grades after the following code executes?

grades[grades.length-1] = grades[2] + grades[3];

Question 17 options:

18. Consider the following two code segments. In both, assume that n is an integer

variable that has been declared and initialized.

Segment 1

int prod = 1;

int i;

for (i = 2; i <= n; i++) {

prod *= i;

}

System.out.println(prod);

Segment 2

int prod = 1;

int i = 2;

while (i <= n) {

prod = prod * i;

i++;

}

System.out.println(prod);

For which integer values of n do these code segments print the same result?

Question 18 options:

19. The following code is intended to calculate the sum of the first five positive even

integers.

int sum = 2, k;

for(k = 4; k <= 12; k += 2)

{

sum += k;

}

What is wrong with this code segment?

Question 19 options:

20. Assume that an array of integers named list has been declared and initialized, and

that an integer named value has been declared and initialized. Consider the following
code:
int counter;
boolean flag = false;
for (counter = 0; counter < list.length; counter++) {
flag = (list[counter] == value);
}
When will the value of flag be true, after this code executes?

Question 20 options:

21. Consider the following code segment:

int i;
for (i = 0; i <= 10; i++) {
if ((i % 3) == 1) {
System.out.print(i + " ");
}
}
What is printed as a result of executing this code segment?

Question 21 options:

22. Which of the following statements is true?

Question 22 options:

25. The Integer.MAX_VALUE constant has the value of ____.

Question 25 options:

26.In the following algorithm, which constant should be assigned to minimum to ensure that the algorithm finds the smallest integer?

Question 26 options:

1) I only 2) II only 3) I and II only 4) II and III only 5) None of the above cause ArrayIndexOutOfBoundsException minimum E constant for (int current 0; current numbers length; current if (minimum numbers current) minimum numbers current];

Explanation / Answer

16) 3. I & II only

17) 5. {88, 92, 95, 178}

18) 5. Any integer n produces the same result

19) 2. The segment calculates the sum of the first six positive even integers.

20) 3. Whenever value is equal to list[i] for some i such that 0 <= i < list.length

21) 5. 1 4 7 10

22) 2. For-each loops can only be used to iterate over all array elements.

25) 2. 231 - 1

26) 1. Integer.MIN_VALUE

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote