13/13

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

```

Replace this line with your code.

<do not remove the three backticks above>
1 Like

import java.util.*;

public class GeneralizationsD {
public static void main(String args) {
// Create the Arraylist!!!
ArrayList sports = new ArrayList();
sports.add(“Football”);
sports.add(“Boxing”);

	for(String sport : sports) {
		System.out.println(sport);
	}

	//Major cities and the year they were founded
	HashMap<String, Integer> majorCities = new HashMap<String, Integer>();

	majorCities.put("New York", 1624);
	majorCities.put("London", 43);
	majorCities.put("Mexico City", 1521);
	majorCities.put("Sao Paulo", 1554);


	for (String city : majorCities.keySet() ) {

		System.out.println(city + " was founded in " + majorCities.get(city));

	}



}

}

I dont know whats wrong with my code…

What makes you say it’s wrong in any way? Please describe what’s going on, ask about what you want to know

Because I get an error “Did you create an ArrayList named sports?”…

ArrayList sports = new ArrayList (); is still not working

I have the same error

public class GeneralizationsD {
public static void main(String args) {
ArrayList sports = new ArrayList();

sports.add("Football");
sports.add("Boxing");

	for(String sport : sports) {
		System.out.println(sport);
	}

	//Major cities and the year they were founded
	HashMap<String, Integer> majorCities = new HashMap<String, Integer>();

	majorCities.put("New York", 1624);
	majorCities.put("London", 43);
	majorCities.put("Mexico City", 1521);
	majorCities.put("Sao Paulo", 1554);

	for (String city : majorCities.keySet()) {

		System.out.println(city + " was founded in " + majorCities.get(city));

	}


}

}
I used that from another post from the forum and it past, but I don’t know why. I don’t see any differences between my code and this…

Thanks
I had the same code and it didnt work
but
CCP works for me :slight_smile:

ArrayList sports = new ArrayList(); the how to make an Array list

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