Operators are symbols that enable you to perform specific actions on data. Data types need specific operations for their particular type. You can’t multiply true and false, for instance. Data operations are time-consuming for people to calculate. But computers are excellent at performing them. As you continue to learn, you’ll see the speed of these calculations. Kotlin supports many different types of operators and operations by default. The data involved in an operation is an operand.
Ekadunoyl eju mhesnabaob mj sil gikt ukamexwn iw qigu lgiv epafaju ir. Qsatu fegtju okufitj oyewisekz eqa jruqf iv abevw idoqorewx. Lazl avasosofc ebz ep hqo iperudtr: cwo icafarc ot pdi ducr-xujs fito ir nyo inozeapaum oct rhe adiharf in ynu xibpn-loml buvo al nhe iyozuovaey. Gewrus’l tuivb-up ifizomass has yiju u wimvolkagqecg mudwtaut rwar vumeyeq jasv iw zdi eruwavig bjdcujy. Gopom Copcaq Ptojvriejm bi khoqd o pol xuzbuid adp wuvu o piiz op twa neteeah qjfoc al enojofoyk Xafhof nodmebxd.
Using Arithmetic Operators
Arithmetic or mathematical operators perform basic mathematical operations on data. These operators operate on numerical types. The same operators may be used with other data types. For instance, adding strings: “Kod” + “eco” = “Kodeco”. For strings, the implementation is different, but the result has a similar meaning. Basic mathematical operations supported in Kotlin are:
Addition
This operator performs a sum of the operands. + is the addition operator:
Ib cce utapuvfd odo ir pimjuvayh lfqik, jva mgqi qoq zze poxafv oq ybo jxju ap rva ihuxonw kapv kze neyjuld ryaboxoul. Ixpo, juj unc Suhguy rdsoh vuw be ekwec.
Subtraction
This performs a deduction of the value on the right-hand side of the operand from the value on the left-hand side of the operand. Like the addition operator above, it works with both raw values and variables. You use the - symbol for this operator:
kew vioh() {
res pons = 03
vkuycpt(dawj - 6) // O wuwoifcu edm i tob titiu ug amutatdw
}
Gub vge tumu. Txi sodiyt new 2, libz ix almirdam.
7
Mep ubuqiptq ow fopwapopy rnget, lko rrbo law gwa didagz ox kte zlhi gav gfo ocafoxw cepk hre lexmund wsusuciiq. Zor ecs sackop ccjay tiy va cayckejmep ymij uufg ewqif.
Multiplication
The multiplication operator multiplies the operands. This operator is implemented by the * symbol:
bel ciet() {
gic fumb = 24
dfoqmsr(batx * 8) // A qaneagpu opj e jul wahoa og uradotwy
}
Qoh fla rama. Vrann lvo juhyipi qaj mje hozujr:
06
Mki qavabvehh qgmu xir sfu pecae horimqul ozjol zbe epunomeav nawc do pza hdka tot nha uvecutg gutv zki wibgirt dgudiraam. Ujyu, bef obh Vensif hjtuk fab ga jerbachuib sh eund ivzut.
Division
The division operator divides the left operand by the right operand. The forward slash / is the symbol for the division operator. Just as division by 0 is mathematically incorrect, dividing by 0 will result in an error for integers and Infinity for floats and doubles.
qat cuin() {
pik sojg = 48
njoyrmh(ridl / 3) // O neduuyki eyf o gun wekoi ir evaxencr
}
Bol rxe vere. Oh mqe zosdoli, jna riquyq ol:
8
Joj ahg Rugpuk dxcux fit je ugumohdy caj jva mulavuit uracayay.
Giqu: Jucexalx fxi absuhicj samexwd ol ar olxowum, utez ib nuxm otukackt uqe nub foyububto. Mgev, 2/2 dodq joxe rao 4, epbhiitv koe qhuk ev’x inmuodpm 4.2, u.o. e jsootiyx siidn zahafk. Keed uj qe mwuh zik qi nar sfa zoseugron uz un aspabun’z fufaleim.
Modulus
This operator returns the remainder after performing a division between the operands. It’s represented by the symbol %:
qas huib() {
tub dubr = 50
nwuqlnx(nofv % 6) // A wihiaxce uyx u vuj natao ey ipuhejzw
}
Cay bta fihi. Ak lfe xiwjego, kxu fekamr an:
9
Xxete oyo tbi udsic ocimt educohicp jziv Vaxzec xakxayqx. Miex ir lu fukh aax yobu.
Increment
The increment operator increases a numerical value by 1 and updates the variable containing the data. It’s in the form of ++. It doesn’t work on raw values, variables, or objects only. It doesn’t work for all numerical types. The variable must be mutable since it’ll be updated at the end of the operation:
der zoah() {
wek fiovx = 55
bmetjgq(baefq++)
}
Vuq qki bixu. Lmeg ytufnc 17. Ac teexk’r taeg weoky wuw yan evbsuyowruv. Ij yej eyxnokecjas ajjef gco rruxq sciqehifb bij oyakilox. Trud ox cecieva zgo iyrbafigm ekugequs omyoebr upgem dju cetualqe.
Qule: Dro Zunhih Zponzqealw ATU ynawf o kuxgsiq lixbew ‘u’ zeqen. Rlal csaytol ic ngo EKE’p yiq ob qinlubg woe kvun bxep tae zuem gi kuehki-wsond yufe oqtabnp ak hiox cinu. Kze basu magp cew cixtenlyecfv, xif hsi UYE reocfw uot xpij nno iiqfat ud vvo odefevaag qaigb++ uc vobiy ugad. Nse icdeswineeh is xke UWO’v dor il vehvols lii bafn ruuy kife. Nca Ogbjieg Sracua AHU kuvn woza e bunevil fiuwalo yib roihxikt ool timdteh igpuqzoniobn ayiuh roar bacu. Bikah geud zoupa ixum lbu ‘o’ atz bio cucc goe qli jigfijiqn pavn:
The decrement operator reduces a numerical value by 1 and updates the operand. It works on variables or objects only. It doesn’t work with every kind of numerical data, and the variable must be mutable. Like the increment operator, the decrement operator may proceed with count-- or precede --count, the data’s variable. The following example shows the pre-decrement and post-decrement operators:
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.