位置:首頁 > 高級語言 > Scala教學 > Scala關係運算符

Scala關係運算符

下麵的簡單示例程序演示的關係運算符。複製並粘貼到一個Test.scala文件中,編譯並運行此Scala程序程序。

object Test {
   def main(args: Array[String]) {
      var a = 10;
      var b = 20;
      println("a == b = " + (a == b) );
      println("a != b = " + (a != b) );
      println("a > b = " + (a > b) );
      println("a < b = " + (a < b) );
      println("b >= a = " + (b >= a) );
      println("b <= a = " + (b <= a) );
   }
}

這將產生以下結果:

C:/>scalac Test.scala
C:/>scala Test
a == b = false
a != b = true
a > b = false
a < b = true
b >= a = true
b <= a = false

C:/>