Println ("greater number is $num2") //greater number is 30 These operators are mostly used with if-else for executing specific flow after comparison. In the above example, the value of b is first incremented by 1 and then assigned to variable ‘increment’, whereas the value of c is first assigned to variable dec and then decreases by 1.Ĭomparison Operators are used for comparing the two values. If the increment or decrement operator is used after a variable name, then its value is changed after the other operation on that variable. If an increment or decrement operator is used before the variable name, then the value of that variable is changed first before any other operation on the variable. Increment and Decrement operators can be used before and after a variable, but both have different meanings. Println ("Negation = $negation") // Negation = -5 println ("Increment = $increment") // Increment = 11 println (“Decrement = $dec”) // Decrement = 15 Increment ( ++ ) and Decrement ( - ) operators are shortcuts of x = x+1 and x = x – 1 Operators Unary Operators are those that work only on a single operand. Println ("Result1 = $number1") // Result1 = 32 println ("Result2 = $number2") // Result2 = 2 Var number1 = 22 var number2 = 20 number1 + = 10 number2 % = 3 Println ("mult = $answer") // mult = 2048īesides the basic = assignment operator, Kotlin provides a wide range of assignment Operators, which are mentioned below: Operator Modulus – returns remainder on dividing two numbers Subtract right operand from the left operand In Kotlin simple a + b is interpreted as a.plus(b) as a function call. Arithmetic OperatorsĪrithmetic Operators are those that are used to perform basic arithmetic calculations like subtraction, addition, multiplication, division, etc. Operators in Kotlin, Here 67 and 7 are operands, and – is an operator.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |