![]() |
VOOZH | about |
The subtractExact(int num1, int num2) is an inbuilt method of StrictMath class in java which is used to get the difference of the given arguments num1 and num2. If the result overflows int, it throws an exception.
Since subtractExact(int num1, int num2) is static, so object creation is not mandatory.
Syntax :
public static int subtractExact(int num1, int num2)
Parameters: The method accepts two parameters:
Return Value: The method returns the difference of the given arguments num1 and num2.
Exception: If the result overflows an int it throws ArithmeticException.
Examples:
Input: num1 = 750, num2 = 50 Output: 700 Input: num1 = 361, num2 = 929 Output: -568
Below program illustrates the java.lang.StrictMath.subtractExact() method:
Program 1:
Difference of 76761 and 99 = 76662 Difference of 76761 and 786616 = -709855
The subtractExact(long num1, long num2) is an inbuilt method of StrictMath class in java which is used to get the difference of the given arguments num1 and num2. If the result overflows long it throws an exception. Since subtractExact(long num1, long num2) is static, so object creation is not mandatory.
Syntax :
public static long subtractExact(long num1, long num2)
Parameters: The method accepts two parameters:
Return Value: The method returns the difference of the given arguments num1 and num2.
Exception: If the result overflows an long it throws ArithmeticException.
Examples:
Input: num1 = 750, num2 = 50 Output: 700 Input: num1 = 361, num2 = 929 Output: -568
Below program illustrates the java.lang.StrictMath.subtractExact() method:
Program 1:
Difference of -76342561 and 949 = -76343510 Difference of -76342561 and 78326616 = -154669177