/* * Copyright (c) 2001 Matthew Feldt. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided the copyright notice above is * retained. * * THIS SOFTWARE IS PROVIDED ''AS IS'' AND WITHOUT ANY EXPRESSED OR * IMPLIED WARRANTIES. */ /** * AvailableLocales.java * * Java Examples In A Nutshell Copyright (c) 2000 David Flanagan * Exercise 7-1: * Several internationalization-related classes, such as NumberFormat and * DateFormat, have static methods named getAvailableLocales() that return an * array of the Locale objects they support. You can look up the name of the * country of a given Locale object with the getDisplayCountry method. Note * that this method has two variants. One takes no arguments and displays the * country name as appropriate in the default locale. The other version of * getDisplayCountry() expects a Locale argument and displays the country * name in the language of the specified locale. * * Write a program that displays the country names for all locales returned by * NumberFormat.getAvailableLocales(). Using the static locale constants * defined by the Locale class, display each country name in English, French, * German, and Italian. * * @author Matthew Feldt * @version 1.0 */ package com.feldt.examples.i18n; import java.text.*; import java.util.*; import java.io.*; public class AvailableLocales { public static void main(String[] args) { Locale[] locale = NumberFormat.getAvailableLocales(); System.out.println("Locales available in NumberFormat"); System.out.println("locale\tCountry\tEnglish\tFrench\tGerman\tItalian"); for (int i = 0; i < locale.length; i++) { System.out.println("[" + i +"]\t" + locale[i].getCountry() + "\t" + locale[i].getDisplayCountry(Locale.ENGLISH) + "\t" + locale[i].getDisplayCountry(Locale.FRENCH) + "\t" + locale[i].getDisplayCountry(Locale.GERMAN) + "\t" + locale[i].getDisplayCountry(Locale.ITALIAN)); } } }