therrontelford

Countries Array

Nov 14th, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. import java.util.Locale;
  2.  
  3. public class Countries {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         // Using Locale class static method getISOCountries()
  8.         // we extract a list of all 2-letter country codes
  9.         // defined in ISO 3166. Can be used to create Locales.
  10.        
  11.         String[] countries = Locale.getISOCountries();
  12.         String[] country = new String[countries.length];
  13.        
  14.         // Loop each country
  15.         for(int i = 0; i < countries.length; i++) {
  16.            
  17.             String c = countries[i];
  18.             Locale locale = new Locale("en", c);
  19.          
  20.             // Get the country name by calling getDisplayCountry()
  21.             String countryName = locale.getDisplayCountry();
  22.             country[i] = countryName;
  23.             System.out.println(country[i]);
  24.            
  25.          
  26.             // Printing the country name on the console
  27.          //System.out.println(i+1 + " : " + countryName);
  28.            
  29.         }      
  30.                
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment