.decrementExact()
Anonymous contributor
Published Oct 23, 2022
Contribute to Docs
The Math.decrementExact()
method returns the argument decremented by one. It throws an exception if the result overflows the specified data type of the argument.
Syntax
Math.decrementExact(num)
The num
parameter is of type long
or int
.
Example
The following example uses the .decrementExact()
method to decrement the input by 1:
// Main.javapublic class Main {public static void main(String[] args) {int value = 21;long input = 123L;long negValue = -38L;System.out.println(Math.decrementExact(value));System.out.println(Math.decrementExact(input));System.out.println(Math.decrementExact(negValue));}}
This will produce the following output:
20122-39
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.