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));
}
}
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.)
ionatan
December 23, 2015, 10:55am
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 }
1 Like
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
kposh
January 3, 2016, 6:27pm
5
Hi all!
Iâve one question⌠here is my excercise
The excercise is apparently âapprovedâ but theres an error on the console. I don
t know which is the part that is well and the one thatâs wrong
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).
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
1 Like
kposh
January 3, 2016, 8:50pm
7
thnx. I finish the âLearn Javaâ and i feel i do not know nothing :Dsweat_smile:
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.
1 Like
Could you explain why the .size() function was used here ?
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) );
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.â
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.
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
1 Like