📜  Scala Int 比较方法与示例

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

Scala Int 比较方法与示例

compare是 Scala 中的 int 类方法,用于将其与该操作数进行比较。

示例 1:

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

示例 2:

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