官术网_书友最值得收藏!

Arithmetic operators

We can perform arithmetic operations using the arithmetic operators. Arithmetic operators contain operators for addition (+), subtraction (-), multiplication (*), division (/), and remainder (%). We've already seen many examples for addition, not mentioning that these operators are methods!

Let's take examples of others:

scala> val x = 10 - 1
x: Int = 9

scala> val y = 10 * 1
y: Int = 10

scala> val z = 10 / 1
z: Int = 10

scala> val yx = 10 % 9
yx: Int = 1

These operators have their overloaded versions also defined, to see that we may try with different types as operands. Let's take an Int and Double:

scala> val yx = 10 % 9.0
yx: Double = 1.0

Here, the first operand is an Int, and the second one is a Double, and since Int is view-bounded to Double, the result is converted to Double.

主站蜘蛛池模板: 正宁县| 新巴尔虎右旗| 普安县| 方正县| 如皋市| 常熟市| 海原县| 合水县| 景德镇市| 宁明县| 华宁县| 横峰县| 虞城县| 永修县| 安丘市| 锦屏县| 封开县| 九江县| 喀喇沁旗| 社会| 河池市| 临海市| 开化县| 东乌| 托克逊县| 朝阳市| 罗定市| 台中县| 太康县| 保山市| 油尖旺区| 铜川市| 清徐县| 仙桃市| 永康市| 河间市| 昭通市| 天长市| 色达县| 宜兴市| 梁河县|