Open In App

Scala Long abs() method with example

The abs() method is utilized to return the absolute value of the given integer value. The absolute value of any number is the magnitude of that number i.e, without any sign.

Method Definition: def abs: Float



Return Type: It return the absolute value of the given integer value.

Example 1:




// Scala program of Long abs()
// method
  
// Creating object
object Test
{
  
    // Main method
    def main(args
             : Array[String])
    {
  
        // Applying abs method
        val res = (-7002).abs
  
                  // Displays output
                  println(res)
    }
}

Output:



7002

Example 2:




// Scala program of Long abs()
// method
  
// Creating object
object Test
{
  
    // Main method
    def main(args : Array[String])
    {
  
        // Applying abs method
        val res = (-7002).abs
  
        // Displays output
        println(res)
    }
}

Output:

23.42

Article Tags :