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., xāˆ’1x-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));
}
}
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
šŸ† Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources