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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。