2015-08-19 06:30:01
阅读( 389 )
下面示例通过Currency类的getInstance()方法获得指定国家的货币信息,然后通过Currency.getSymbol()获得其货币符号。
package cn.outofmemory.examples;
import java.util.Currency;
import java.util.Locale;
/**
*
* @author outofmemory.cn
*/
public class Main {
public void displayCurrencySymbols() {
Currency currency = Currency.getInstance(Locale.US);
System.out.println("United States: " + currency.getSymbol());
currency = Currency.getInstance(Locale.UK);
System.out.println("United Kingdom: " + currency.getSymbol());
currency = Currency.getInstance(Locale.FRANCE);
System.out.println("France: " + currency.getSymbol());
}
public static void main(String[] args) {
new Main().displayCurrencySymbols();
}
}
上述代码将输出:
United States: USD
United Kingdom: GBP
France: €
分享给朋友:
亲~ 如果您有更好的答案 可在评论区发表您独到的见解。
您想查看更多的信息:
面试题