Kotlin Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
fun main(args: Array<String>) { val val1 = 7.3 val val2 = 3.2 var result: Double result = val1 + val2 println("val1 + val2 = $result") result = val1 - val2 println("val1 - val2 = $result") result = val1 * val2 println("val1 * val2 = $result") result = val1 / val2 println("val1 / val2 = $result") result = val1 % val2 println("val1 % val2 = $result") } |
Output:
1 2 3 4 5 6 7 |
val1 + val2 = 10.5 val1 - val2 = 4.1 val1 * val2 = 23.36 val1 / val2 = 2.28125 val1 % val2 = 0.8999999999999995 |
Kotlin programming language supports various arithmetic operators for all floating-point and integer numbers. These operators are + (addition), – (subtraction), * (multiplication), / (division), and % (modulo).
Above program explains about the all arithmetic operations.
The + operator is also used for the concatenation of String values.