decrementExact(): This method is available in the Math class of Java.
Syntax:
int java.lang.Math.decrementExact(int a)
This method takes one argument of type int. This method returns the argument decremented by one. It throwing an exception if the result overflows an int.The overflow only occurs for the minimum value.
Parameters: One parameter is required for this method.
a: the value to decrement.
Returns: the result.
Note: It Throws ArithmeticException - if the result overflows an int.
For Example:
decrementExact(10) = > It return 9 (i.e decrement one from 10).
Approach
Java
public class DecrementExactInt {public static void main(String[] args) {int x = 10;System.out.println(Math.decrementExact(x));}}
Output:
9
No comments:
Post a Comment