Kotlin Data Types

Chapter: Kotlin Last Updated: 12-11-2017 14:18:26 UTC

Program:

            /* ............... START ............... */
                
fun main(args : Array<String>) {

    // Byte Type
    val temp: Byte = 80
    println("$temp")

    // Short Type
    val score: Short = 2345
    println("$score")

    // Int Type
    val result: Int =  100000
    println("$result")

    // Long Type
    val long_Val: Long = 7878
    println("$long_Val")

    // Double Type
    val double_Val: Double = 107.8
    println("$double_Val")

    // Float Type
    val float_Val = 10.6F
    println("$float_Val")

    // Char Example
    val char_Example: Char
    char_Example = 'K'
    println("$char_Example")

    // Boolean Example
    val flag = true
    println("$flag")
}
                /* ............... END ............... */
        

Output

80
2345
100000
7878
107.8
10.6
K
true

Notes:

  • Above Kotlin program example to show data types Numbers, Characters and boolean.
  • Byte : The Byte data type can have values from -128 to 127 (8-bit signed two's complement integer).
  • Short : The Short data type can have values from -32768 to 32767 (16-bit signed two's complement integer).
  • Int : The Int data type can have values from -2^31 to 2^31 – 1 (32 bit signed 2’s complement integer).
  • Long : The Long data type can have values from -2^63 to 2^63 – 1 (64 bit signed 2’s complement integer).
  • Double : The Double type is a double-precision 64-bit floating point. If you assign a floating point value to a variable and do not declare the data type explicitly, it is inferred as Double data type variable by the compiler.
  • Float : The Float data type is a single-precision 32-bit floating point.
  • Char : Characters are represented by the type Char. You need to use single quotes ‘ ‘ to denote a character. For example : 'C','K'
  • Boolean : As like Java Boolean data type has two possible values, either true or false.

Tags

Data Types Example , Kotlin, Numbers, Characters , boolean

Similar Programs Chapter Last Updated
Kotlin Continue Kotlin 02-03-2018
Kotlin Break Statement Kotlin 27-01-2018
Kotlin For Loop Kotlin 30-11-2017
Kotlin Do While Loop Kotlin 19-11-2017
Kotlin While Loop Kotlin 19-11-2017
Kotlin When Statement Kotlin 18-11-2017
Kotlin Nested If Kotlin 18-11-2017
Kotlin If Else If Statement Kotlin 18-11-2017
Kotlin If Statement Kotlin 17-11-2017
Kotlin Print And Println Kotlin 17-11-2017
Kotlin Type Conversion Kotlin 17-11-2017
Kotlin Logical Operators Kotlin 17-11-2017
Kotlin Assignment Operators Kotlin 15-11-2017
Kotlin Arithmetic Operators Kotlin 15-11-2017
Kotlin Variables Example Kotlin 11-11-2017
Kotlin Comments Example Kotlin 11-11-2017
Kotlin Hello World Kotlin 11-11-2017

1