java中multiply用法_Java Math multiplyFull()用法及代码示例

Math类的multipleFull(int x,int y)方法用于返回两个参数的精确数学乘积。在参数中,提供了两个整数值,并且此方法以长型表示两个数字的乘积。

用法:

public static long multiplyFull(int x, int y)

参数:此方法接受两个Integer x,y作为参数,其中x和y是要相乘的参数。

返回值:此方法返回long类型值,该值是X * Y的精确乘积。

注意:此方法已添加到JDK 9中。因此,它将无法在Online IDE上运行。

以下示例程序旨在说明multiplyFull()方法:

示例1:

// Java program to demonstrate

// multiplyFull() method of Math class

public class GFG {

// Main method

public static void main(String[] args)

{

// two Integer values

int a = 367428, b = 1374;

// apply multiplyFull method

long c = Math.multiplyFull(a, b);

// print result

System.out.println(a + " * "

+ b + " = " + c);

}

}

输出:

367428 * 1374 = 504846072

示例2:两个整数相乘包含Integer.MAX值。

// Java program to demonstrate

// multiplyFull() method of Math class

public class GFG {

// Main method

public static void main(String[] args)

{

// two Integer values

int a = Integer.MAX_VALUE;

int b = Integer.MAX_VALUE;

// apply multiplyFull method

long c = Math.multiplyFull(a, b);

// print result

System.out.println(a + " * "

+ b + " = " + c);

}

}

输出:

2147483647 * 2147483647 = 4611686014132420609

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值