Java.lang Package Classes

Java Math - decrementExact() Method



The java.lang.Math.decrementExact() method returns the argument decreased by one. It throws an exception, if the result overflows a long.

Syntax

public static long decrementExact(long a)  

Parameters

a Specify the value to decrement.

Return Value

Returns the argument decreased by one.

Exception

Throws ArithmeticException, if the result overflows a long.

Example:

In the example below, decrementExact() method is used to decrease the argument by one.

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  long i = 0;
  long j = 145;
  System.out.println(Math.decrementExact(i)); 
  System.out.println(Math.decrementExact(j));    
 }
}

The output of the above code will be:

-1
144

❮ Java.lang - Math