Math multiplyFull() method in Java with Examples
Last Updated :
24 Apr, 2023
The multiplyFull(int x, int y) method of Math class is used to return the exact mathematical product of the two arguments. In the parameters, two integer values are provided and the product of both numbers expressed in long type returned by this method.
Syntax:
public static long multiplyFull(int x, int y)
Parameters: This method accepts two Integer x, y as parameter where x and y are arguments to be multiplied.
Return Value: This method returns long type value which is exact product of X * Y.
Note: This method is added in JDK 9. Hence it won’t run on Online IDE. Below programs illustrate the multiplyFull() method:
Program 1:
Java
public class GFG {
public static void main(String[] args)
{
int a = 367428 , b = 1374 ;
long c = Math.multiplyFull(a, b);
System.out.println(a + " * " + b + " = " + c);
}
}
|
Output:
367428 * 1374 = 504846072
Program 2: Multiplying two integers contains Integer.MAX values.
Java
public class GFG {
public static void main(String[] args)
{
int a = Integer.MAX_VALUE;
int b = Integer.MAX_VALUE;
long c = Math.multiplyFull(a, b);
System.out.println(a + " * " + b + " = " + c);
}
}
|
Output:
2147483647 * 2147483647 = 4611686014132420609
Example 3:
Java
import java.io.*;
import java.lang.Math;
public class GFG {
public static void main(String[] args)
{
int x = 200000 ;
int y = 300000 ;
long result = Math.multiplyFull(x, y);
System.out.println( "Result: " + result);
}
}
|
Output
Result: 60000000000
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...