📜  Scala Int CompareTo 方法与示例

📅  最后修改于: 2022-05-13 01:54:23.027000             🧑  作者: Mango

Scala Int CompareTo 方法与示例

compareTo是 Scala 中的一个 int 类方法,用于将其与该操作数进行比较。它类似于比较方法。

示例 1:

Scala
// Scala Program to demonstrate the
// compareTo method of Int class
 
object GfG
{
  
    // Main Method
    def main(args:Array[String])
    {
      
        // Applying the method
        val v1 = (500).compareTo(400)
          
        // Displaying the output
        println(v1)
      
    }
}


Scala
// Scala Program to demonstrate the
// compareTo method of Int class
 
object GfG
{
  
    // Main Method
    def main(args:Array[String])
    {
      
        // Applying the method
        val v1 = (200).compareTo(700)
          
        // Displaying the output
        println(v1)
      
    }
}


输出:
1

示例 2:

斯卡拉

// Scala Program to demonstrate the
// compareTo method of Int class
 
object GfG
{
  
    // Main Method
    def main(args:Array[String])
    {
      
        // Applying the method
        val v1 = (200).compareTo(700)
          
        // Displaying the output
        println(v1)
      
    }
}
输出:
-1