bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java Math subtractExact() Method

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Java Math subtractExact() Method?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___()
3Order

Put the learning moves in the order that makes the concept easiest to apply.

The subtractExact() method subtracts two integers and throws an exception if the subtraction causes an overflow.
Definition and Usage
Java Math subtractExact() Method

❮ Math Methods

subtractExact()

Definition and Usage

The subtractExact() method subtracts two integers and throws an exception if the subtraction causes an overflow. This prevents incorrect results that can occur from subtracting really large negative numbers.

One of the following

public static int subtractExact(int
x , int
y )
public static long subtractExact(long
x , long
y )

Parameter Values

ParameterDescription
xRequired. The number to subtract from.
yRequired. The amount to subtract.

Technical Details

Returns:An int or long value representing the subtraction of two numbers.
Throws:ArithmeticException - If the subtraction causes an overflow.
Java version:1.8+

Previous

Java Math sqrt() Method

Next

Java Math tan() Method