Open In App

Scala Int abs() method with example

Improve
Improve
Like Article
Like
Save
Share
Report

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: (Signed_Integer_Value).abs
Return Type: It return the absolute value of the given signed integer value.

Example #1:




// Scala program of Int abs()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying abs method
        val result = (-5).abs
          
        // Displays output
        println(result)
      
    }


Output:

5

Example #2:




// Scala program of Int abs()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying abs method
        val result = (+65).abs
          
        // Displays output
        println(result)
      
    }


Output:

65


Last Updated : 03 Nov, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads