bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java Math addExact() Method

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Java Math addExact() 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.

___.out.println(Math.addExact(12, 16));
3Order

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

The addExact() method adds two integers and throws an exception if the addition causes an overflow.
Definition and Usage
Java Math addExact() Method

❮ Math Methods

Example

System.out.println(Math.addExact(12, 16));
System.out.println(Math.addExact(10000, 24060));

Definition and Usage

The addExact() method adds two integers and throws an exception if the addition causes an overflow. This prevents incorrect results that can occur from adding really large numbers.

One of the following

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

Parameter Values

ParameterDescription
xRequired. The first number to be added.
yRequired. The second number to be added.

Technical Details

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

Previous

Java Math acos() Method

Next

Java Math asin() Method