13/13


#1

import java.util.*;

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

	for(String sport : sports) {

ArrayList sports = new
ArrayList();
}

	//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 () {

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

	}

*/

}

}

This is what my code looks like, but I'm not exactly sure how to do this: "Inside of the main method and before the for each loop, create an ArrayList called sports that stores String types."


#2

import java.util.*;

public class GeneralizationsD {
	public static void main(String[] args) {
//                       Create the Arraylist!!!
		ArrayList<String> sports = new ArrayList<String>();
		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));

		}



	}
}

You didn't add the array list correctly, nor did you get it on the objected directed towards.


#3

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