Kotlin Lec 1 2020
Kotlin Lec 1 2020
Программирование на Kotlin
(p.1 - basics)
This might not seem particularly interesting, but it may be if you have seen other
programming languages. Many do not allow you to nest comments like this
Printing out
• It’s also useful to see the results of what your
code is doing.
• In Kotlin, you can achieve this through the use
of the println command.
• println will output whatever you want to the
console.
For example, consider the following code:
println("Hello from Kotlin!")
Printing out
Arithmetic operations
The digits that come in to fill the empty spots on the right become 0.
The digits that fall off the end on the left are lost. Shifting right is the
same, but the digits move to the right.
Shift operations
The Kotlin functions for these two operations
are as follows:
• Shift left: shl
• Shift right: shr
These are infix functions that you place in
between the operands so that the function call
looks like an operation:
1 shl 3
32 shr 2
Order of operations
When you calculate a value, you’ll want to use
multiple operators:
(((12000 / (4 * 10)) - 32) shr (29 % 5)) + 26
() parentheses
. Accessing to class (object) member
The type Int can store integers. The way you store
decimal numbers is like so:
val pi: Double = 3.14159
fun main() {
print("Input a number:")
val x = readLine()!!.toInt()
println("Your number is $x")
}
Using meaningful names
Программирование на Kotlin
(p.1 - basics)