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

multiplyExact()

Example

Perform integer multiplication using the multiplyExact() method in Java.

System.out.println(Math.multiplyExact(96000, 1200));
System.out.println(Math.multiplyExact(-460, 95));

Definition and Usage

The multiplyExact() method in Java computes the product of two integers while detecting and handling overflow situations by throwing an exception, ensuring accurate results, particularly when dealing with large numbers.

Syntax

One of the following:

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

Parameter Values

Parameter

Description

x

Please provide the first number to be multiplied.

y

Please provide the second number to be multiplied.

Technical Details

Returns:

A result represented as an int or long, obtained by multiplying two numbers.

Throws:

An ArithmeticException is thrown if the multiplication operation results in an overflow.

Java Version:

1.8+