Lesson 7 Programming in Kotlin math operations

in #programming7 years ago

Lesson 7 Programming in Kotlin

 math operations

![Kotlin-logo.png]()

 We use the combination of the symbol (+) to subtract the symbol (-) to divide the symbol (/) to multiplication  the symbol (*)  

And do not forget the priorities of calculations as in mathematics, where we adopt the following order in precedence 1-  ()

2 - Multiplication and division where they have the same power so if they come in the same statement we start the process on the left

 3. Addition and subtraction, such as division and multiplication

 4. Equality == 

Example: 

fun main (args: Array <String>)

       print ("enter first number: \ n") 

       var umber1 = readLine () !!. toDouble () 

      print ("enter second number: \ n") 

      var number2 = readLine () !!. toDouble () 

/ * So far we have asked the user to enter two numbers and store the values ​​in variables number1, number2 For instance, we have two methods * / 

The first method 

var sum: Double? 

sum = number1 + number2 

print ("sum = $ sum") 

// The way for a second 

We write directly 

print (number1 + number2) 

Or print ("sum = $ {number1 + number2}")   
in this example we use new symbols \ n and $ what do they mean  

\n means go to a new line such as println  

$ Means put the value of sum in this place when we wrote  

print ("sum = $ sum") 

 It is as we say show on the screen  sum = result  For the rest of the operations it is similar   

Q: Write a program asking the user to enter two numbers and then print the results of addition, subtraction, multiplication and division  

Sort:  

Congratulations @marksadow! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of posts published

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Coin Marketplace

STEEM 0.27
TRX 0.21
JST 0.038
BTC 96978.60
ETH 3697.93
USDT 1.00
SBD 3.87