Scala Int abs() 方法与示例
abs()方法用于返回给定整数值的绝对值。任何数字的绝对值是该数字的大小,即没有任何符号。
Method Definition: (Signed_Integer_Value).abs
Return Type: It return the absolute value of the given signed integer value.
示例 #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)
}
}
输出:
5
示例 #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)
}
}
输出:
65