Lesson 5: Arraylist

This lesson has been nothing but trouble.

Here is the set up of the problem:

import java.util.ArrayList;

public class Temperatures {
	
	public static void main(String[] args) {

    ArrayList<Integer> weeklyTemperatures = new ArrayList<Integer>();

    weeklyTemperatures.add(78);
    weeklyTemperatures.add(67);
    weeklyTemperatures.add(89);
    weeklyTemperatures.add(94);
 
    System.out.printIn( weeklyTemperatures.get(0) );

Of course, I type the answer correct but it says incorrect for lowest temperature.

I want to understand what I’m doing wrong.

Is it my answer or the white space?

We do not see a closing brace for your main method or for the class. Did you just not paste them in to the post, or are they actually missing?

It’s there.

import java.util.ArrayList;

public class Temperatures {

public static void main(String[] args) {

ArrayList<Integer> weeklyTemperatures = new ArrayList<Integer>();

weeklyTemperatures.add(78);
weeklyTemperatures.add(67);
weeklyTemperatures.add(89);
weeklyTemperatures.add(94);

System.out.printIn( weeklyTemperatures.get(0) );

}

}

Perhaps the white space is tripping up the SCT…

System.out.println(weeklyTemperatures.get(0));

ArrayList Access

Still getting the same wrong answer. I think it’s a glitch but I know it’s the right answer.

1 Like

What do you mean the SCT??

Have you tried refreshing the session? A different browser? If all else fails, can you Get Code?

Submission Correctness Test

The program that runs in the background behind each lesson page. It is not exhaustive, sometimes fickle and other times lenient.

I have tried you have suggested to me and get still the same results. After I get the code it’s correct but the spaces move the code slightly. I don’t know why. Maybe space sensitive?

So, the SCT is sometimes not going to work on a lesson, correct?

Perhaps not as we expect it might. For the most part, when the instructions have been followed exactly and correctly the lessons pass as expected.

Alright, thank you mtf.

You are most helpful.

1 Like

You’re supposed to print the lowest temperature but you’re printing the first. 67 is the lowest temperature so the last line of your code should be

System.out.printIn( weeklyTemperatures.get(1) )

Wording left me stumped too.

If you’re feeling a bit adventurous you could write a for loop to check for the lowest temperature.

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