5/13


#1

"ArrayLists in Java are zero-indexed, which means that the first element in an ArrayList is at a position of 0."

The code example:

ArrayList quizGrades = new ArrayList();
quizGrades.add(95);
quizGrades.add(87);
quizGrades.add(73);

System.out.println( quizGrades.get(0) );

Yet the correct code is " System.out.println( weeklyTemperatures.get(1) );"

So the correct way to choose the first in an index is "1" not "0"?


#2

1 does not come before 0 and 0 is an index, so 0 is the first index.
Maybe you weren't meant to select the first index?

The main method is intended to look like:

public static void main(String[] args) {
    ArrayList<Integer> weeklyTemperatures = new ArrayList<Integer>();
    weeklyTemperatures.add(78);
    weeklyTemperatures.add(67);
    weeklyTemperatures.add(89);
    weeklyTemperatures.add(94);
}

And the exercise asks to use get to obtain the lowest temperature which is 67 which is at index 1.

However, adding the numbers in a different order makes the checkpoint behave poorly, as it doesn't actually check which is lowest and just assumes your code looks like above.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.