Home Kotlin
Post
Cancel

Kotlin

1
2
3
fun main() {
    println("Hello, World!")
}

Datatypes

1
2
3
4
5
6
7
8
9
var number = 5
val constant = 5 //val is final

//it's possible to specify a type
val myNum: Int = 5                // Int
val myDoubleNum: Double = 5.99    // Double
val myLetter: Char = 'D'          // Char
val myBoolean: Boolean = true     // Boolean
val myText: String = "Hello"      // String

Operators

Arithmetic

OperatorNameExample
+Additionx + y
-Subtractionx - y
*Multiplicationx * y
/Divisionx / y
%Modulusx % y
++Incrementi++
Decrementi--

Assignment

OperatorExampleSame As
=x = 5x + y
+=x += 5x = x + 5
-=x -= 5x = x - 5
*=x *= 5x = x * 5
/=x /= 5x = x / 5
%=x %= 5x = x % 5

Comparison

OperatorNameExample
==equal tox == y
!=not equal tox != y
>greater thanx > y
<less thanx < y
>=greater than or equal tox >= y
<=less than or equal tox <= y

Logical

OperatorNameDescriptionExample
&&ANDreturns true if both statements are truex < 5 && x < 10
||ORreturns true if one of the statements is truex < 5 || x < 4
!NOTreverse the result, returns false if the result is true!(x < 5 && x < 10)
This post is licensed under CC BY 4.0 by the author.