Scala算术运算符

于2017-07-06由小牛君创建

分享到:


试试下面的例子就明白了所有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:/>