.decrementExact()
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
Contributors
- Anonymous contributor