当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Scala Long abs()用法及代码示例

abs()方法用于返回给定整数值的绝对值。任何数字的绝对值是该数字的大小,即没有任何符号。

函数定义: def abs: Float

返回类型: It return the absolute value of the given integer value.



范例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) 
    } 
}

输出:

7002

范例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) 
    } 
}

输出:

23.42



注:本文由纯净天空筛选整理自Shubrodeep Banerjee大神的英文原创作品 Scala Long abs() method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。