Java BigInteger类| valueOf()方法与示例

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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值