1.2-Kotlin Datatypes, Operators
1.2-Kotlin Datatypes, Operators
Module 1-Introduction
Operators
Data Types
2
Recap of Var vs Val
fun main()
{
var 1=“Hi students”
println(1)
}
3
Kotlin - Data types
4
Kotlin - Data types
In Kotlin, the type of a variable is decided by its value:
5
Kotlin - Data types
6
Kotlin - Data types
Floating Point
Numbers String Boolean
Numbers
• Byte - 8 bit [- • Float - 32 bit • char
• Boolean
128 to 127] • Double - 64 • String
• Short - 16 bit bit
[-32768 to
32767]
• Int - 32 bit [-
231 to 231-1]
• Long - 64 bit
[-263 to 263-
1]
7
Operators in Koltin
Arithmetic operator
Relational operator
Unary operator
Bitwise operator
Logical operator
Assignment operator
8
1. Arithmetic Operators
9
Example program
fun main (args : Array <String>) fun main (args : Array <String>)
{ {
var num1 = 64 val fname = “Sundar"
var num2 = 32 val lname = “Pichai"
val answer : double val full_name = fname + " " + lname
answer = num1 +num2 println (full_name)
println ("sum = $answer") }
answer = num1 - num2
println ("diff = $answer")
answer =num1 * num2
println ("mult = $answer")
answer = num1 / num2
println ("div = $answer")
answer = num1 % num2
println ("mod = $answer")
}
10
2. Assignment Operators
11
3. Unary Operators
12
4. Comparison Operators
13
5. Equality and Non-equality Operators
14
6. Logical Operators
15
7. In Operator
16
7. In Operator – Example Code
It is better to use a shortcut and define the range specifying the
lowest and highest value.
18
8. Range Operator
19
8. Range Operator – Example Code
21
9. Indexed Access Operator – Example Code
23
10. Bitwise Operators – Example Code
fun main (args : Array <String>)
{
var a = 12
var b = 10
val result1 : Int
val result2 : Int
result1 = a and b
result2 = a or b
println ("final result of and operation is $result1")
println("final result of or operation is $result2“)
} 24
Thank You!!!
25