Add integers:
System. |
The addExact() method adds two integers but raises an exception if the sum exceeds the maximum value that the integer type can hold, ensuring accurate calculations and preventing potential errors resulting from integer overflow.
The addExact() method adds two integers, but if the result exceeds the maximum value allowed for the integer type, it triggers an exception, safeguarding against inaccuracies due to overflow.
public |
public |
Parameter |
Description |
x |
Necessary. The initial number to be added. |
y |
Mandatory. The second number to be added. |
Returns: |
An integer or long value representing the result of adding two numbers together. |
Throws: |
ArithmeticException occurs if the addition results in an overflow. |
Java Version: |
1.8+ |