7/13 data structures not working


#1

I have everything correct i think. Why is it not working?

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

It prints everything out....not sure what the problem is, says (Use the example to help you create the for loop and use the get method.)


#3

Perhaps it's looking directly at your code and is looking for "j++", but that's not how you wrote it.

Also you're missing a }


#4

Hey @tagrunner10039 you missing a bracket at the end.

Your missing

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

}<<-- Add a bracket here

#5

Hi all!

I've one question... here is my excercise

The excercise is apparently "approved" but theres an error on the console. I dont know which is the part that is well and the one that's wrong :confused:
I mean, in some excercises i feel that the only thing that i must do is copying the example. In this case, i do not really understand which is the function of the 'size' method (sometimes it might be because my matern lang is spanish, but i do not have problems understanding the concept of the exercises but the terminology it results confusing in some moments).


#6

It expects more }'s to close your {'s - or possibly another kind of brackets. Instead it reached the end of the file.

ArrayList's size method returns the number of elements in an ArrayList


#7

thnx. I finish the "Learn Java" and i feel i do not know nothing :Dsweat_smile:


#8

If you want to practice Java, just as a suggestion, check out www.codewars.com
They give you a small task to implement, and once you've solved it you get to see how others did it.
Remember to google whenever you don't know how to do something.


#9

great! thanks man! :+1:


#10

Could you explain why the .size() function was used here ?


#11

Should anything be printed into the console? with the code:

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

#12

code is not working.....

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

plzz tell me what's the problem wid this code...
i am getting notified like this

"Use the example to help you create the for loop and use the get method."


#13

Guys, i got the same problem as arccoder94360, my code prints out all elements of array, but i got the error: Use the example to help you create the for loop and use the get method.


#14

create a new topic
1.go to this link https://discuss.codecademy.com/c/learn-java/data-structures
2.click on +New Topic
3.read the froum carefully, post your code and tell us your problem
4.done


#17