Java Math multiplyExact() Method

Facebooktwitterredditpinterestlinkedinmailby feather

The multiplyExact() method of Math class returns the product of the argument, throwing an exception if the result overflows an int or a long.

Syntax:

  1. public static int multiplyExact (int x, int y)
  2. public static long multiplyExact (long x, int y)
  3. public static long multiplyExact (long x, long y)

Parameters:

The parameters ‘x’ and ‘y’ represent the first and second value.

Return Value:

The multiplyExact () method returns the product of the arguments x and y.

Throws:

The multiplyExact () method throws:

ArithmeticException- if the result overflows an int or long.

 Example 1:

Output:

Example 2:

Output:

Example 3:

Output:

Example 4:

Output:

Facebooktwitterredditpinterestlinkedinmailby feather