### Scala arithmetic operations in detail

530 total views,  5 views today

Welcome to Scala series. In this tutorial, you will learn about Scala arithmetic operations in detail.

Arithmetic operations are basically mathematical operations such as Addition.subtraction,division,multiplication and modulo.

Below are the basic arithmetic operations supported by Scala

1. + (add two values and generate the result)
2. – (Subtract two values and generate the result)
3. * (Multiple two values and generate the result)
4. / (Divide two values and generate the result)
5. % (Returns the reminder)

In Scala, each arithmetic operation is a function.That is ,it can be invoked with .+() notation

`` result = test.+(10)``

This is also equal to,

``  result = test + 10``

Both are valid and it depends on the readability. I prefer is the second option as it is very simple to use and understand.

Let us see an example for each operation.

### Multiply example

```
var test: Int = 100;

//Multiply
var result = test.*(2) // Option 1

println(result)

result = test * 2 // Option 2

println(result)```

Output

``````200
200``````

```var test: Int = 100;

var result = test.+(2) // Option 1

println(result)

result = test + 2 // Option 2

println(result)```

Output

``````102
102``````

### Subtraction example

```var test: Int = 100;

//Subtraction
var result = test.-(2) // Option 1

println(result)

result = test - 2 // Option 2

println(result)```

Output

``````98
98``````

### Division example

```var test: Int = 100;

//Subtraction
var result = test./(2)

println(result)

result = test / 2

println(result)```

Output

``````50
50``````

### Modulo example

```var test: Int = 100;

//Subtraction
var result = test.%(2)

println(result)

result = test % 2

println(result)```

Output

``````0
0``````

### Complete example of arithmetic operations

``` object StaticReference {

def main(args: Array[String]) {

var test: Int = 100;

//Multiply
var result = test.*(2)

println(result)

result = test * 2

println(result)

result = test.+(10)

println(result)

result = test + 10

println(result)

//Subtraction

result = test.-(10)

println(result)

result = test - 10

println(result)

//Division

result = test./(10)

println(result)

result = test / 10

println(result)

}
}```

References Official documentation

Tags :

#### Rajasekar

Hey There, My name is Rajasekar and I am the author of this site. I hope you are liking my tutorials and references. Programming and learning new technologies are my passion. The ultimate idea of this site is to share my knowledge(I am still a learner :)) and help you out!. Please spread your words about us (staticreference.com) and give a thumbs up :) Feel free to contact me for any queries!.

## 37 thoughts on “Scala arithmetic operations in detail”

• I am truly happy to read this web site posts which carries tons
of useful data, thanks for providing these kinds
of data.

• Since the admin of this website is working, no uncertainty very rapidly it will be well-known, due to its quality contents.

• Wonderful beat ! I wish to apprentice while you amend your site, how
can i subscribe for a blog website? The account helped me a acceptable deal.
concept

• Heya i am for the primary time here. I came across this board
and I to find It really useful & it helped me out much.

I’m hoping to present something back and aid others like you helped me.

• You ought to be a part of a contest for one of the best sites on the internet.
I’m going to highly recommend this site!

• Wow, that’s what I was exploring for, what a stuff!
present here at this weblog, thanks admin of this site.

• Heya this is somewhat of off topic but I was wanting to know if
blogs use WYSIWYG editors or if you have to manually code with HTML.
I’m starting a blog soon but have no coding
expertise so I wanted to get advice from someone with experience.

Any help would be enormously appreciated!

• Appreciate the recommendation. Will try it out.

• It’s a shame you don’t have a donate button! I’d most certainly donate to this outstanding blog!

Chat soon!

• Excellent beat ! I wish to apprentice even as you amend your
website, how can i subscribe for a blog web site? The account helped me a applicable deal.
I were a little bit familiar of this your broadcast provided vibrant transparent concept

• You should take part in a contest for one of the best websites on the
web. I am going to highly recommend this website!

• Excellent blog right here! Also your site rather a lot up very fast!

What host are you the usage of? Can I am getting your affiliate
up as quickly as yours lol

• This is very fascinating, You’re an excessively professional blogger.

wonderful post. Additionally, I have shared your
web site in my social networks

• Hey! Quick question that’s entirely off topic.
Do you know how to make your site mobile friendly? My site looks weird when browsing from my iphone.
I’m trying to find a template or plugin that might be able to correct this issue.
If you have any suggestions, please share. Appreciate it!

• Hello! I know this is somewhat off topic but I was wondering which blog platform are you using for this website?
I’m getting sick and tired of WordPress because I’ve had issues with hackers and I’m looking at alternatives for
another platform. I would be awesome if you could point me in the direction of a good platform.

• Saved as a favorite, I really like your blog!

• This design is wicked! You certainly know how to keep a reader amused.
to start my own blog (well, almost…HaHa!) Excellent job.
I really enjoyed what you had to say, and more than that,
how you presented it. Too cool!

• Thanks for a marvelous posting! I truly enjoyed reading it,
you could be a great author. I will remember to bookmark your blog and definitely will come back
from now on. I want to encourage you to ultimately
continue your great writing, have a nice evening!

• It’s going to be end of mine day, except before
finish I am reading this fantastic article to increase my experience.

• Hey There. I found your blog using msn. This is a very
well written article. I will be sure to bookmark it and return to
read more of your useful information. Thanks for the post. I will definitely return.

• It’s really very complex in this busy life
to listen news on Television, thus I simply use world wide web for
that purpose, and obtain the newest information.

• Major thankies for the blog post.Thanks Again. Will read on…

• Gute Arbeit. Danke.

• Asking questions are genuinely good thing if you are not understanding something completely, but this paragraph
provides pleasant understanding even.

• I really enjoy looking at on this website , it contains great articles. “I have a new philosophy. I’m only going to dread one day at a time.” by Charles M. Schulz.

• Do you have a spam problem on this blog; I also am a blogger, and I was wanting to know your situation; we have developed some nice practices and we are looking to swap solutions with others, why not shoot me an email if interested.

• Yeah I do have a lot of spam problems..Will contact you shortly

• Gut geschrieben. Echt toll. Danke.

• Vielen Dank für den tollen Artikel.