In this guide, we will discuss Scala Arithmetic Operators. Try the following example program to understand all the arithmetic operators available in Scala Programming Language.
Example
object Demo { 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) ); } }
Save the above program in Demo.scala. The following commands are used to compile and execute this program.
Command
\>scalac Demo.scala \>scala Demo
Output
a + b = 30 a - b = -10 a * b = 200 b / a = 2 b % a = 0 c % a = 5
Next Topic : Click Here
Pingback: Scala - Operators | Adglob Infosystem Pvt Ltd