Iterating over an ArrayList - 7/13


#1



https://www.codecademy.com/en/courses/learn-java/lessons/data-structures/exercises/arraylist-iterating?action=resume


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

	}
}


#2

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


#3

@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


#4
       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!

#5

It may be helpful


#6

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


#7

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.


#8

Thanks will tell you when I passed the level


#9

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


#10

It is only possible after completing level.


#11

It seems very impossible it could be a bug


#12

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


#13

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