java 方法 示例
货币类getSymbol()方法 (Currency Class getSymbol() method)
Syntax:
句法:
public String getSymbol();
public String getSymbol(Locale lo);
getSymbol() method is available in java.util package.
getSymbol()方法在java.util包中可用。
getSymbol() method is used to get the symbol of this Currency for the default locale.
getSymbol()方法用于获取默认语言环境的货币符号。
getSymbol(Locale lo) method is used to get the symbol of this Currency for the given Locale (lo).
getSymbol(Locale lo)方法用于获取给定Locale(lo)的此货币的符号。
getSymbol() method does not throw an exception at the time of returning symbol.
getSymbol()方法在返回符号时不会引发异常。
getSymbol(Locale lo) method may throw an exception at the time of returning symbol.
getSymbol(Locale lo)方法在返回符号时可能会引发异常。
NullPointerException: This exception may throw when the given parameter Locale (lo) is null exists.
NullPointerException :如果给定参数Locale(lo)为null,则可能引发此异常。
These are non-static methods, it is accessible with class object & if we try to access these methods with the class name then we will get an error.
这些是非静态方法,可通过类对象访问;如果尝试使用类名称访问这些方法,则会收到错误消息。
Parameter(s):
参数:
In the first case, getSymbol(),
在第一种情况下, getSymbol() ,
- It does not accept any parameter.
In the second case, getSymbol(Locale lo)
在第二种情况下, getSymbol(Locale lo)
- Locale lo – represent the locale for whose symbol is to be returned.
- 语言环境lo –表示要为其返回符号的语言环境。
Return value:
返回值:
In both the cases, the return type of the method is String, it gets symbol of this Currency object.
在这两种情况下,方法的返回类型均为String ,它获取此Currency对象的符号。
Example:
例:
// Java program is to demonstrate the example of
// getSymbol() method of Currency
import java.util.*;
public class GetSymbolOfCurrency {
public static void main(String args[]) {
// Instantiates a currency with INR code
// for the default locale
Currency c1 = Currency.getInstance("INR");
// Instantiates a currency for the given locale
Locale lo = Locale.US;
Currency c2 = Currency.getInstance(lo);
// By using getSymbol() method is to return
// the symbol of this Currency for the
// default locale
System.out.print("c1.getSymbol(): ");
System.out.println(c1.getSymbol());
// By using getSymbol(lo) method is to return
// the symbol of this Currency for the
// defined locale
System.out.print("c2.getSymbol(lo): ");
System.out.println(c2.getSymbol(lo));
}
}
Output
输出量
c1.getSymbol(): ₹
c2.getSymbol(lo): $
翻译自: https://www.includehelp.com/java/currency-getsymbol-method-with-example.aspx
java 方法 示例