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
Operator | Name | Example |
---|---|---|
+ | Addition | x + y |
- | Subtraction | x - y |
* | Multiplication | x * y |
/ | Division | x / y |
% | Modulus | x % y |
++ | Increment | i++ |
– | Decrement | i-- |
Assignment
Operator | Example | Same As |
---|---|---|
= | x = 5 | x + y |
+= | x += 5 | x = x + 5 |
-= | x -= 5 | x = x - 5 |
*= | x *= 5 | x = x * 5 |
/= | x /= 5 | x = x / 5 |
%= | x %= 5 | x = x % 5 |
Comparison
Operator | Name | Example |
---|---|---|
== | equal to | x == y |
!= | not equal to | x != y |
> | greater than | x > y |
< | less than | x < y |
>= | greater than or equal to | x >= y |
<= | less than or equal to | x <= y |
Logical
Operator | Name | Description | Example |
---|---|---|---|
&& | AND | returns true if both statements are true | x < 5 && x < 10 |
|| | OR | returns true if one of the statements is true | x < 5 || x < 4 |
! | NOT | reverse the result, returns false if the result is true | !(x < 5 && x < 10) |