Iterating over an ArrayList - 7/13

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/en/courses/learn-java/lessons/data-structures/exercises/arraylist-iterating?action=resume

<In what way does your code behave incorrectly? Include ALL error messages.>
Use the example to help you create the for loop and use the get method.

TemperaturesC.java:13: error: ‘)’ expected
for (int j = 0; j < weeklyTemperatures.size(); j++ {
^
TemperaturesC.java:18: error: reached end of file while parsing
}
^
2 errors

```

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

}

}

<do not remove the three backticks above>

is syntax error, you forget two things,
1- ) in after j++
2- close block by } in for or void main()

@technut123,
You are forgetting a closing-parentheses-) in the definition of your FOR-loop
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html
https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

google search
== the Book ==
java [your question] site:oracle.com

1 Like
       Thank you so much, @leonhard.wettengmx.n! Sometimes, there are little mistakes I don't notice. Probably not something i want to maintain if I want to work at Google one day!

It may be helpful

I have the same code as you and it is not working for me. What should I do?https://www.codecademy.com/courses/learn-java/lessons/data-structures/exercises/arraylist-iterating?action=lesson_resume&link_content_target=interstitial_lesson

You can wait some days and then try again inputting same code to the
system. Though I don’t know whether it is solution or not. But believe me,
I did same things when I found such case in codeacademy systems. Best of
Luck.

Thanks will tell you when I passed the level

Can anyone explain why we added .size in
for (int j = 0 ; j < weeklyTemperatures.size(); j ++) {
System.out.println(weeklyTemperatures.get(i) );

what does it mean ?

Thank you

It is only possible after completing level.

It seems very impossible it could be a bug

look closer that the variables you are using, ask yourself where are you getting the “i” variable from?

you use .size to tell that “j” will be compared against the size of the array… so if the array has 5 spaces, you are sayingt hat you want to be sure “J” is smaller than 5 which is the value of “Size” but the idea is to use something that will just say “compare this agains whatever the current size is…”

HTH,

-KP