程序下方打印出符合ISO 4217货币代码的货币符号.
import java.util.*;
public class Currency{
public static void main(String args[]) {
Currency myInstance = Currency.getInstance(args[0]);
System.out.println(myInstance.getSymbol());
}
}
Run Code Online (Sandbox Code Playgroud)
问题:输入字符串USD时工作正常.对于像EUR这样的其他输入,只需返回货币代码.
样本输入,来自程序的输出:
input: java Currency USD
output: $
input: java Currency EUR
output: EUR -> I expect the symbol of Euro here
Run Code Online (Sandbox Code Playgroud)
pol*_*nts 25
Currency.getSymbol()
返回相对于默认语言环境的货币符号.
获取默认语言环境的此货币的符号.例如,对于美元,符号是
"$"
默认区域设置是美国,而对于其他区域设置,它可能是"US$"
.如果无法确定符号,则返回ISO 4217货币代码.
使用Currency.getSymbol(Locale locale)
,如果你想为不同的语言环境的符号.
System.out.println(
Currency.getInstance("USD").getSymbol(Locale.US)
);
// prints $
System.out.println(
Currency.getInstance("USD").getSymbol(Locale.FRANCE)
);
// prints USD
System.out.println(
Currency.getInstance("EUR").getSymbol(Locale.US)
);
// prints EUR
System.out.println(
Currency.getInstance("EUR").getSymbol(Locale.FRANCE)
);
// prints €
Run Code Online (Sandbox Code Playgroud)
(另见ideone.com).
归档时间: |
|
查看次数: |
16697 次 |
最近记录: |