Java Math negateExact() Method

Facebooktwitterredditpinterestlinkedinmailby feather

The negateExact() method of Math class returns the negation for the specified argument, throwing an exception if the result overflows an int or a long.

Syntax:

  1. public static int negateExact (int a)
  2. public static long negateExact (long a)

Parameters:

The parameter ‘a’ represents the value to negate.

Return Value:

The negateExact () method returns the negation of a.

Throws:

The negateExact () 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