What is Math.multiplyFull in Java?

Overview

multiplyFull is a static method in the Math class in Java. It is used to return the exact mathematical product of two integer numbers.

This method was introduced in Java 9. Hence, it’s important to use Java 9 and above versions to use this function.

The multiplyFull method is defined in the Math class. The Math class is defined in the java.lang package.

To import the Math class, check the following import statement.

import java.lang.Math;

Method signature

public static long multiplyFull(int x, int y)

Parameters

int x: the first integer value to be multiplied.
int y: the second integer value to be multiplied.

Return value:

This method returns the product as long datatype.

Examples

In the code below, we define two integers and a long result variable to hold the result of the product.

import java.lang.Math;
public class Main {
public static void main(String[] args) {
int firstValue = 12345678;
int secondValue = 987654321;
long result = Math.multiplyFull(firstValue, secondValue);
System.out.println("Result - " + result);
}
}

In the code below, we use the maximum value and minimum value an integer datatype can hold as the values to be multiplied.

import java.lang.Math;
public class Main {
public static void main(String[] args) {
int firstValue = Integer.MAX_VALUE;
int secondValue = Integer.MIN_VALUE;
long result = Math.multiplyFull(firstValue, secondValue);
System.out.println("Result - " + result);
}
}

Free Resources