Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

scala
math
sum
communitycreator

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

Hammad Nasir

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

Syntax

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

Parameters

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

Return value

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

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

Code

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

RELATED TAGS

scala
math
sum
communitycreator
RELATED COURSES

View all Courses

Keep Exploring