TemperaturesB exercise


#1

Instructions asked me to insert a new temperature (111) into index two of the array list. Why is this code wrong? I added the print console command at the end to get the value at index 2 and it returned the right number, but I still have the error message and it won't let me proceed.

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(111);
	weeklyTemperatures.add(89);
	weeklyTemperatures.add(94);

#2

Haven't done this yet, so it's just a little "you could try this", but maybe it wants you to use "weeklyTemperatures.add(111,2)" at the end instead?


#3

perhaps its because you never closed your class

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(111);
	weeklyTemperatures.add(89);
	weeklyTemperatures.add(94);
}//end main
}//end class

#4

They want you to do weeklyTemperatures.add(2,111);


#5

It would be "weeklyTemperatures.add(2, 111);"


#6

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