Use the get method to print out the temperature 89


#1

guys please help me ,i can't figure it out what is wrong with my code and why is saying me that the index is not ok

import java.util.ArrayList;

public class TemperaturesB {
	
	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);
    System.out.println( weeklyTemperatures.get(2) );
   System.out.println( weeklyTemperatures.get(3) );


	}
}

#2
[78, 67, 111, 89, 94]
      ^
   .get(1)

#3

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