Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

scala
math
sum
communitycreator

What is addExact(x: Int, y: Int) in Scala?

Hammad Nasir

addExact(x: Int, y: Int) is a function in the math package in Scala. The addExact() function calculates the sum of its arguments.

Syntax

def addExact(x: Int, y: Int): Int

Parameters

The function takes in two parameters, x and y. Both parameters are of type int.

Return value

The function returns the sum of x and y. The value is of type int.

The function throws ArithmeticException if the int is overflowed by adding x and y.

Code

object MainObject {
  def main(args: Array[String]) {
    var x : Int = 22;
    var y : Int = 23;
    println("Math.addExact(x, y) = "+ Math.addExact(x, y)); 
  }
}

RELATED TAGS

scala
math
sum
communitycreator
RELATED COURSES

View all Courses

Keep Exploring