TreeMap Iteration Tutorial

From Progzoo
Jump to: navigation, search

Iterating over the world.

We can iterate over the structure world.values() if we want to process every single country.

Print the name and area of every country in South America.

You may use the following format string to print the details:

"%-21s%9d\n"

[Font] [Default] [Show] [Resize] [History] [Profile]

Large Countries

Print the name of each country with a population of at least 200 million.

[Font] [Default] [Show] [Resize] [History] [Profile]

Countries beginning with J

Print the name of each country where the name begins with "J"

[Font] [Default] [Show] [Resize] [History] [Profile]

Countries with a larger GDP than UK

Print the name of each country where GDP is greater than that of "United Kingdom"

(The data is a little old)

[Font] [Default] [Show] [Resize] [History] [Profile]

OPEC.

The countries of OPEC in 2005 are Algeria, Libya, Nigeria, Iran, Iraq, Kuwait, Qatar, Saudi Arabia, United Arab Emerates, Venezuela and Indonesia.

For each of the countries of OPEC, print the name and the GDP.

[Font] [Default] [Show] [Resize] [History] [Profile]

OPEC and the Middle East.

We can use an if statement to ensure that only some countries are printed. Do not change the opec list for this question.

For each of the countries of OPEC, print the name and the GDP - only for those OPEC members in the Middle East.

[Font] [Default] [Show] [Resize] [History] [Profile]