bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java Math subtractExact() Method

❮ Math Methods

subtractExact()

Definition and Usage

The subtractExact() method subtracts two integers and throws an exception if the subtraction causes an overflow. This prevents incorrect results that can occur from subtracting really large negative numbers.

One of the following

public static int subtractExact(int
x , int
y )
public static long subtractExact(long
x , long
y )

Parameter Values

ParameterDescription
xRequired. The number to subtract from.
yRequired. The amount to subtract.

Technical Details

Returns:An int or long value representing the subtraction of two numbers.
Throws:ArithmeticException - If the subtraction causes an overflow.
Java version:1.8+

Previous

Java Math sqrt() Method

Next

Java Math tan() Method