Index Problem


#1

I know you guys are probably tired of seeing my name
post in these forums lol but in need of some help again.
I'm trying to add the temperature 111 to the "0" spot in my
index & I keep getting an error doing it.

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(0, 111);


}
}

Also, can someone give me a future tip on posting code?
I use Ctrl + K to use Pre-formatted text but when I use it
and copy the code it formats some of the lines and other lines
will be in regular text like this & it just makes it messier than it
already is. Thanks in advance Codecademy!

Edit: I figured it out guys. The instructions we're telling me to
set the temperature at index "2" and for some reason I kept trying
to put it at 0. Sorry for the wasted thread.


#2

@kodeman89

Sorry about the very late response. I see you figured out the answer, so I'd ask that you please mark this topic as solved. In addition, you asked how to post code, and I'd be happy to help...

If you are posting a single word, or line of code, then you should use the back-tick surrounding your code. This will result in the following: code

For something longer, like the above posted, you seem to have figured it out. Simply copy and paste the code in your editor directly into the edit box of the message, select it, and press the </> button. Once you have it selected, you can also press Control+Shift+C, which will accomplish the same thing. This will result in the following:

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(0, 111);


     }
}

With the above, you may have to use the spacebar to move a curly brace a little bit, like I did above for the second to last one. For reference, 4 spaces equals one tab mark, so that should help you with the formatting.

I hope this helps, let me know if you need anything else, and if I can, I'll be happy to help. Good luck. :coffee:


#4