Scala Long -(x: Int) 方法
在Scala中,Long是一个64位有符号整数,相当于Java的long原始类型。利用 – ( x: Int) 方法,可以返回这个值与给定值x的差值。
方法定义 – def -(x: Int):Long
返回 – 返回此值与 x 的总和。
例子 #1 :
// Scala program to explain the working
// of Long -(x: Int) method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying -(x: Int) function
val result = (12.0021.toLong).-(8:Int)
// Displays output
println(result)
}
}
输出。
4
例子#2
// Scala program to explain the working
// of Long -(x: Int) method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying -(x: Int) function
val result = (16.0123.toLong).-(13:Int)
// Displays output
println(result)
}
}
输出。
3
极客教程