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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
    }
}

chevron_right


Output:

7002

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
    }
}

chevron_right


Output:

23.42



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.