Why isn't one line shown in the output


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-java/lessons/data-structures/exercises/arraylist-iterating?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>
It behaves fine, I just have a question. Why isn’t the bottom line weeklyTemperatures.add(2, 111);
outputted? It finishes at 94

```

Replace this line with your code.
import java.util.ArrayList;

public class TemperaturesC {

public static void main(String[] args) {

	ArrayList<Integer> weeklyTemperatures = new ArrayList<Integer>();
	weeklyTemperatures.add(78);
	weeklyTemperatures.add(67);
	weeklyTemperatures.add(89);
	weeklyTemperatures.add(94);
	weeklyTemperatures.add(2, 111);

for (int j = 0; j < weeklyTemperatures.size(); j++) {

System.out.println( weeklyTemperatures.get(j) );

}

}

}

<do not remove the three backticks above>

#2

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