It is a built-in function in Java, that is used to multiply the two values that are passed as arguments to the function. Here’s an example −
Example
import java.lang.Math; public class Demo{ public static void main(String args[]){ int a = 12, b = 34; System.out.printf("Product is : "); System.out.println(Math.multiplyExact(a, b)); long c = 78, d = 93; System.out.printf("Product is : "); System.out.println(Math.multiplyExact(c, d)); } }
Output
Product is : 408 Product is : 7254
A class named Demo contains the main function. Here, two variables are defined, and their product is calculated using the ‘multiplyExact’ function. Now two long integers are defined and again, their product is computed using the ‘multiplyExact’ function. Next, they are printed on the console.