Java Tutorial Java Advanced Java Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Java - Math decrementExact() Method



The Java Math decrementExact() method returns the argument decreased by one. The method can be overloaded and it can take int and long arguments. It throws an exception, if the result overflows an int or a long.

Syntax

public static int decrementExact(int x)  
public static long decrementExact(long x)  

Parameters

x Specify the value.

Return Value

Returns the argument decreased by one.

Exception

throws ArithmeticException, if the result overflows an int or a long.

Exception

NA.

Example:

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

public class MyClass {
 public static void main(String[] args) {
  int 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 Math Methods

5