Lesson 5: Arraylist


#1

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?


#2

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?


#3

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

}

}


#4

Perhaps the white space is tripping up the SCT…

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

ArrayList Access


#5

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


#6

What do you mean the SCT??


#7

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.


#8

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?


#9

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.


#10

Alright, thank you mtf.

You are most helpful.


#11

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.


#12

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