What is decrementExact(x: Int) in Scala?

decrementExact(x: Int) is a function in the Math package of Scala that decreases the argument by 1 and returns it.

Syntax


def decrementExact(x: Int): Int

Parameters

The function takes in one parameter, x, of type int.

Return value

The decrementExact() function returns the value of x decreased by 1, i.e., x1x-1.


The function throws ArithmeticException if int is overflowed by the return value.

Code

object MainObject {
def main(args: Array[String]): Unit = {
var x : Int = 130;
println("Math.decrementExact(x) = " + Math.decrementExact(x));
}
}

Free Resources