Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

decrementExact()

Example

Decrease various numbers by one.

System.out.println(Math.decrementExact(12002));
System.out.println(Math.decrementExact(18));
System.out.println(Math.decrementExact(32));
System.out.println(Math.decrementExact(947));

Definition and Usage

The decrementExact() method subtracts 1 from a given integer and throws an exception if an overflow occurs, ensuring accurate results and preventing potential errors.

Syntax

One of the following:

public static int decrementExact(int x)

 

public static long decrementExact(long x)

Parameter Values

Parameter

Description

x

Needed: An integer to be decremented from.

Technical Details

Returns:

An int or long value representing an integer that is decreased by one.

Throws:

ArithmeticException occurs if the decrement operation leads to an overflow.

Java Version:

1.8+