這幾天面試真的都是被打臉, 有面試官問我Kotlin的變數基本型態有那些,當下我答得不好. 像這種基本型態的問題.... 都需要隨時複習一次. Kotlin has the following basic data types: 1. Numbers – Byte, Short, Int, Long, Float, Double 2. Boolean – True, false 3. Characters: Char 4. Arrays // val numbers = IntArray(5) 5. Strings Type Size Range Byte 8 bits -128 to 127 Short 16 bits -32,768 to 32,767 Int 32 bits -2,147,483,648 to 2,147,483,647 Long 64 bits -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 Every number type has the following conversion functions: toByte(): Byte toShort(): Short toInt(): Int toLong(): Long toFloat(): Float toDouble(): Double toChar(): Char fun main() { val x:Long = 23_334 val y:Int = x.toInt() println(x) println(y) } 基本上面試官問這種問題,實在不恰當,這種東西是屬於 reference 性質, 就算背的苦瓜爛熟,又有何用? ---- char: fun main() { for (c in 'a'..'k') print("$c ") println() for (c in 'k' downTo 'a') print("$c ") } . ------ @JvmStatic fun calcute_total_ele