A symbol that instructs the compiler to perform specified mathematical or logical operations is known as an operator. Scala has a lot of built-in operators, and in this post, we’ll talk about Arithmetic Operators.
The supplied operands are added using the + (Plus) symbol.
To subtract the second operand from the first, use the – (Minus) symbol.
The specified operands are multiplied using the symbol * (Asterisk).
To divide the numerator by the de-numerator, use the symbol / (Slash).
% (Percentage) Symbol is used to find the remainder after division of one number by another.
Let’s see how it works.
Scala> 2.2 + 3.8
res0: Double = 6.0
Scala> 2 + 3
res1: Int = 5
Scala> 2.2 * 3.3
res2: Double = 7.26
Scala> 3.3-2.2
res3: Double = 1.0999
Scala> 34/2
res4: Int = 17
Scala> 34%2.5
res5: Double = 1.5
Hope you find this article helpful.
Please subscribe for more interesting updates.