Scala Arithmetic Operators


Advertisements


Try following example to understand all the arithmetic operators available in Scala Programming Language. Copy and paste the following Scala program in Test.scala file and compile and run this program.

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

This would produce the following result:

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:/>

scala_operators.htm

Advertisements