Javatpoint Logo
Javatpoint Logo

Java Math.decrementExact() method

The java.lang.Math.decrementExact() returns the argument decremented by one. It will throw an exception if the result overflows either int or long.

Syntax

Parameter

Return

  • If the argument is Integer.MIN_VALUE or Long.MIN_VALUE, it will throw an ArithmeticException.

Example 1

Test it Now

Output:

829

Example 2

Test it Now

Output:

-382

Example 3

Test it Now

Output:

Exception in thread "main" java.lang.ArithmeticException: integer overflow
	at java.lang.Math.decrementExact(Math.java:943)
	at decrementExactExample3.main(decrementExactExample3.java:7)

Example 4

Test it Now

Output:

Exception in thread "main" java.lang.ArithmeticException: long overflow
	at java.lang.Math.decrementExact(Math.java:960)
	at decrementExactExample4.main(decrementExactExample4.java:7)

Next TopicJava Math





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA