当前位置:网站首页>Kotlin basic data type

Kotlin basic data type

2022-07-04 19:42:00 AdleyTales

fun main() {
    

    //  Basic numerical type :
    // Double Float Long Int Short Byte

    //  Use underscores to make numeric constants easier to read 
    val oneMillion = 1_000_000
    val creditCardNumber = 1234_5678_9012_3456L

    // 2  Base with  0b  start :0b00001011
    val bytes = 0b11010010_01101001_10010100_10010010

    //  Compare two numbers 
    //  stay  Kotlin  in , Three equal signs  ===  Represents the address of the comparison object , Two  ==  Indicates comparing the size of two values ; Same as JavaScript
    val a: Int? = 10000
    val b: Int? = 10000
    println(a == b) // true
    println(a === b) // false
    println(a === a) // true

    //  Type conversion 
    // toByte() toInt() toShort() toLong() toFloat() toDouble() toChar()

    //  Boolean  true false

    //  Array 
    //  There are two ways to create an array : One is to use functions arrayOf(); The other is to use factory functions . As shown below , We created two arrays in two ways 
    val arr = arrayOf(11, 22, 33)
    println(arr)
    for (i in arr) {
    
        println(i)
    }

    // 2
    val arr2 = Array(10) {
     x -> x }
    for (i in arr2) {
    
        println(i)
    }

    //  character string 
    val text = """  Multiline string   Multiline string  """
    println(text)

}

原网站

版权声明
本文为[AdleyTales]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207041807344997.html