「Scala入門」算術演算子のサンプル

書式

演算子	例	意味
+	x + y	加算
-	x - y	減算
*	x * y	乗算
/	x / y	除算
%	x % y	剰余

使用例

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) );
      
   }
}

実行結果
a + b = 30
a – b = -10
a * b = 200
b / a = 2
b % a = 0
c % a = 5

Scala

Posted by arkgame