incrementExact(): This method is available in the Math class of Java.
Syntax:
long java.lang.Math.incrementExact(long a)
This method takes one argument of type long as its parameter. This method returns the argument incremented by one, throwing an exception if the result overflows a long. The overflow only occurs for the maximum value.
Parameters: One parameter is required for this method.
a: The value to increment.
Note: It Throws: ArithmeticException - if the result overflows a long.
For Example:
Math.incrementExact(1919191) = > It returns 1919192
Approach
Java
public class IncrementExactLong {public static void main(String[] args) {long a = 1919191;System.out.println(Math.incrementExact(a));}}
Output:
1919192
No comments:
Post a Comment