BigInteger类的valueOf()方法 (BigInteger Class valueOf() method)
valueOf() method is available in java.math package.
valueOf()方法在java.math包中可用。
valueOf() method is used to represent the given long value into a BigInteger.
valueOf()方法用于将给定的long值表示为BigInteger。
valueOf() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
valueOf()方法是一个静态方法,可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误。
valueOf() method does not throw an exception at the time of representing the long value.
在表示long值时, valueOf()方法不会引发异常。
Syntax:
句法:
public BigInteger valueOf(long val);
Parameter(s):
参数:
long val – represents the long value to be returned in terms of BigInteger.
long val –表示要以BigInteger形式返回的long值。
Return value:
返回值:
The return type of this method is BigInteger, it returns BigInteger of the given long value.
此方法的返回类型为BigInteger ,它返回给定long值的BigInteger。
Example:
例:
// Java program to demonstrate the example
// of BigInteger valueOf(long val) method of BigInteger
import java.math.*;
public class ValueOfOfBI {
public static void main(String args[]) {
// Instantiates a variable l_val
long l_val = 125487312456l;
// Here, this method valueOf(long) is used
// to convert the given long value into
// a BigInteger and store it in a variable
// named value_of
BigInteger value_of = BigInteger.valueOf(l_val);
System.out.println("l_val: " + l_val);
System.out.println("valueOf(long): ");
// Display value_of
System.out.println("BigInteger.valueOf(l_val): " + value_of);
}
}
Output
输出量
l_val: 125487312456
valueOf(long):
BigInteger.valueOf(l_val): 125487312456
翻译自: https://www.includehelp.com/java/biginteger-valueof-method-with-example.aspx