7 | Iterating over a array list


#1


My code seems to be working fine and am able to print the output also. But I am getting the Error "Use the example to help you create the for loop and use the get method."


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

	}
}


#2

That course uses regexes too much and is therefore often more concerned with what the author anticipated than with what meets what the instructions describe.

I suggest cleaning up the formatting and trying to get it as close as possible to any examples that you were meant to follow

This funny thing is what you need to satisfy:

/for\s*\(\s*int\s+j\s*=\s*0;\s*j\s*<\s*weeklyTemperatures\.size\(\s*\)\s*;\s*j\+\+\)\s*\{\s*System\.out\.println\s*\(\s*weeklyTemperatures\.get\(\s*j\s*\)\s*\)\s*;\s*\}/

As you can see it's a huge mess and what passes is limited by the imagination and thoroughness of the person who wrote that pattern.


#3

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