Monday 20 November 2017

Data types in Kotlin

Java has primitive types like int, float, char etc., what about Kotlin?
In Users point of view, kotlin designed everything as object, but at run time Booleans, numbers and characters are represented as primitive types.

HelloWorld.kt
fun main(args: Array<String>) {
 var doubleVar: Double = 1.23
 var floatVar: Float = 1.23f
 var longVar: Long = 123
 var intVar: Int = 123
 var shortVar: Short = 123
 var byteVar: Byte = 123


 println("doubleVar : ${doubleVar}")
 println("doubleVar : ${floatVar}")
 println("longVar : ${longVar}")
 println("intVar : ${intVar}")
 println("shortVar : ${shortVar}")
 println("byteVar : ${byteVar}")
}

Output
doubleVar : 1.23
doubleVar : 1.23
longVar : 123
intVar : 123
shortVar : 123
byteVar : 123


Previous                                                 Next                                                 Home

No comments:

Post a Comment