Java中的Currency类的getSymbol()方法用于检索货币代码的正式符号。
用法:
CURRENCY.getSymbol()
参数:此方法不接受任何参数。
返回值:此方法返回货币的官方符号。
异常:如果调用了无效的代码,该方法将引发运行时错误。
以下示例程序旨在说明getSymbol()方法的用法:
示例1:
// Java Code to illustrate getSymbol() method
import java.util.*;
public class Currency_Demo {
public static void main(String[] args)
{
// Creating a currency with the code
Currency curr_ency
= Currency.getInstance("INR");
// Getting the symbol of the currency
String currency_symbol
= curr_ency.getSymbol();
System.out.println("Symbol for the currency of India is: "
+ currency_symbol);
}
}
输出:
Symbol for the currency of India is: INR
示例2:
// Java Code to illustrate getSymbol() method
import java.util.*;
public class Currency_Demo {
public static void main(String[] args)
{
// Creating a currency with the code
Currency curr_ency
= Currency.getInstance("USD");
// Getting the symbol of the currency
String currency_symbol
= curr_ency.getSymbol();
System.out.println("Symbol for the currency of USA is: "
+ currency_symbol);
}
}
输出:
Symbol for the currency of USA is: $
示例3:输入无效的货币代码。
// Java Code to illustrate getSymbol() method
import java.util.*;
public class Currency_Demo {
public static void main(String[] args)
{
try {
// Creating a currency with the code
Currency curr_ency
= Currency.getInstance("USDA");
// Getting the symbol of the currency
String currency_symbol
= curr_ency.getSymbol();
System.out.println("Symbol for the currency of USA is: "
+ currency_symbol);
}
catch (Exception e) {
System.out.println(e);
}
}
}
输出:
java.lang.IllegalArgumentException
相关用法
- Java Currency getCurrencyCode()用法及代码示例
- Java Currency getDefaultFractionDigits()用法及代码示例
- Java Currency getInstance()用法及代码示例
- Java Currency toString()用法及代码示例
- Java Java lang.Long.highestOneBit()用法及代码示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代码示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代码示例
- Java Java.util.Collections.rotate()用法及代码示例
- Java Java lang.Long.byteValue()用法及代码示例
- Java Java.util.Collections.disjoint()用法及代码示例
- Java Java lang.Long.lowestOneBit()用法及代码示例
- Java Java lang.Long.reverse()用法及代码示例
- Java Java lang.Long.builtcount()用法及代码示例
注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 Currency getSymbol Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。