8/13


#1


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) );

}

	for (Integer temperature : weeklyTemperatures) {
		 System.out.println(temperature);

}

}

}

what is wrong with my code? Help Please Im stucked. :frowning:


Replace this line with your code.


#2

Hi there,

Nothing sticks out too much.

Although I must warn you that in your second for statement, you've used the wrapper class representation for int. I'd advise looking up the difference between primitive datatypes and their respective wrapper classes for best use case scenarios. I'd recommend checking out the official documentation on this very topic.

What I mean:

for (Integer temperature : weeklyTemperatures)

Could also be:

for (int temperature : weeklyTemperatures)

Apart from that all I can think of that may change the outcome of this:

  1. Are you suppose to add weeklyTemperatures.add(2, 111); after the first for loop to demonstrate your ability to insert values into a given index? If so then that might help.
  2. Try resetting the exercise. Bottom right where it say "Help". Click that and confirm that you wish to reset the exercise.

Let me know if any of that solves your issue.


#3

hi Angesbeef, so I used the same code that I posted and it worked. I think it is a bug or something or the cached needed to be cleared. Thank you so much!


#4

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