Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

scala

What is the incrementExact() method in Scala?

Abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The incrementExact() method is a static method of the math package in Scala that increments the value of the passed argument by 1. The argument’s value remains the same, and the method returns a new value.

The method accepts arguments of type int or long.

Syntax

Math.incrementExact(x) where x can be an int or a long.

Return value

This method returns the incremented value of x by 1.

Example

import scala.math
object Main extends App {
val x = -3
println(s"Number = ${x}")
val newNum = math.incrementExact(x)
println(s"Number after incrementExact = ${newNum}")
}
The incrementExact() method in Scala

Explanation

  • Line 1: Import the math package.
  • Line 4: An integer x is defined.
  • Line 5: Print the x.
  • Line 6:The value of x is incremented by 1 using the incrementExact() method. The value returned is stored in newNum.
  • Line 7:Print the newNum.

RELATED TAGS

scala

CONTRIBUTOR

Abhilash
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring