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

incrementExact()

Example

Increase various numbers.

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

Definition and Usage

The incrementExact() method increments a specified integer by 1 and throws an exception in case of overflow, ensuring accurate results.

Syntax

One of the following:

public static int incrementExact(int x) 
public static long incrementExact(long x

Parameter Values

Parameter

Description

x

Necessary: An integer to increment.

Technical Details

Returns:

An int or long value representing an integer incremented by one.

Throws:

ArithmeticException – Thrown if the increment results in an overflow.

Java Version:

1.8+