- Learning Scala Programming
- Vikash Sharma
- 152字
- 2021-06-30 19:07:52
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.
推薦閱讀
- 深入理解Bootstrap
- Developing Middleware in Java EE 8
- 數(shù)據(jù)結(jié)構(gòu)(Java語(yǔ)言描述)
- VSTO開發(fā)入門教程
- Python應(yīng)用輕松入門
- Internet of Things with ESP8266
- Mastering Python Design Patterns
- 深度學(xué)習(xí)原理與PyTorch實(shí)戰(zhàn)(第2版)
- Image Processing with ImageJ
- Continuous Delivery and DevOps:A Quickstart Guide Second Edition
- Getting Started with Web Components
- 例說FPGA:可直接用于工程項(xiàng)目的第一手經(jīng)驗(yàn)
- Building Web and Mobile ArcGIS Server Applications with JavaScript(Second Edition)
- Leaflet.js Essentials
- Natural Language Processing with Python Cookbook