Scala Float abs() 方法示例
abs() 方法用于返回给定整数值的绝对值。任何数的绝对值都是该数的大小,即没有符号。
方法定义: def abs: Float
返回类型: 返回给定整数值的绝对值。
示例1:
// Scala program of Float abs()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying abs method
val result = (-5.4).abs
// Displays output
println(result)
}
}
5.4
示例2:
// Scala program of Float abs()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying abs method
val result = (3.8).abs
// Displays output
println(result)
}
}
3.8
更多Scala相关文章,请阅读:Scala 教程
极客教程