09.10.2014 Views

Download Scala Tutorial (PDF Version) - Tutorials Point

Download Scala Tutorial (PDF Version) - Tutorials Point

Download Scala Tutorial (PDF Version) - Tutorials Point

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER<br />

7<br />

<strong>Scala</strong> Operators<br />

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.<br />

<strong>Scala</strong> is rich in built-in operators and provides the following types of operators:<br />

<br />

<br />

<br />

<br />

<br />

Arithmetic Operators<br />

Relational Operators<br />

Logical Operators<br />

Bitwise Operators<br />

Assignment Operators<br />

This chapter will examine the arithmetic, relational, logical, bitwise, assignment and other operators one by one.<br />

Arithmetic Operators:<br />

There are the following arithmetic operators supported by <strong>Scala</strong> language:<br />

Assume variable A holds 10 and variable B holds 20, then:<br />

Operator Description<br />

Example<br />

+ Adds two operands A + B will give 30<br />

- Subtracts second operand from the first A - B will give -10<br />

* Multiplies both operands A * B will give 200<br />

/ Divides numerator by de-numerator B / A will give 2<br />

% Modulus Operator and remainder of after an integer division B % A will give 0<br />

Example:<br />

Try the following example to understand all the arithmetic operators available in <strong>Scala</strong> Programming Language.<br />

Copy and paste the following <strong>Scala</strong> program in Test.scala file and compile and run this program.<br />

object Test {<br />

def main(args: Array[String]) {<br />

TUTORIALS POINT<br />

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!