Consider the following method countNegatives, which searches an ArrayList of Integer objects and returns the number of elements in the list that are less than 0. public static int countNegatives(ArrayList arr){int count = 0; for (int j = 0; j < arr.size(); j++) // Line 4{if (arr.get(j) < 0){count++;}}return count;}
Which of the following best explains the impact to the countNegatives method when, in line 4, j < arr.size() is replaced with j <= arr.size() - 1 ?
A. It has no impact on the behavior of the method.
B. It causes the method to ignore the last element in arr.
C. It causes the method to throw an IndexOutOfBounds exception.
D. It reduces the size of arr by 1 and the last element will be removed.
E. It changes the number of times the loop executes, but all indexes in arr will still be accessed.



Answer :

Other Questions