13/13


#1



Replace this line with your code.


#2

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...


#3

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


#4

Because I get an error "Did you create an ArrayList named sports?"....


#5

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


#6

I have the same error


#7

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...


#8

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


#9

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


#10

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