Scala算術運算符
試試下麵的例子就明白了所有Scala編程語言中可用的算術運算符。複製並粘貼以下Scala程序在Test.scala文件中,編譯並運行此程序。
object Test { def main(args: Array[String]) { var a = 10; var b = 20; var c = 25; var d = 25; 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) ); println("c % a = " + (c % a) ); } }
這將產生以下結果:
C:/>scalac Test.scala C:/>scala Test a + b = 30 a - b = -10 a * b = 200 b / a = 2 b % a = 0 c % a = 5 C:/>