当前位置:网站首页>kotlin 基本数据类型
kotlin 基本数据类型
2022-07-04 18:32:00 【AdleyTales】
fun main() {
// 基本数值类型:
// Double Float Long Int Short Byte
// 使用下划线使数字常量更易读
val oneMillion = 1_000_000
val creditCardNumber = 1234_5678_9012_3456L
// 2 进制以 0b 开头:0b00001011
val bytes = 0b11010010_01101001_10010100_10010010
// 比较两个数字
// 在 Kotlin 中,三个等号 === 表示比较对象地址,两个 == 表示比较两个值大小;同JavaScript
val a: Int? = 10000
val b: Int? = 10000
println(a == b) // true
println(a === b) // false
println(a === a) // true
// 类型转化
// toByte() toInt() toShort() toLong() toFloat() toDouble() toChar()
// 布尔 true false
// 数组
// 数组的创建两种方式:一种是使用函数arrayOf();另外一种是使用工厂函数。如下所示,我们分别是两种方式创建了两个数组
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)
}
// 字符串
val text = """ 多行字符串 多行字符串 """
println(text)
}
边栏推荐
猜你喜欢
Lm10 cosine wave homeopathic grid strategy
Pytorch学习(四)
关于判断点是否位于轮廓内的一点思考
node_ Exporter deployment
English grammar_ Noun - use
The 300th weekly match of leetcode (20220703)
OpenCV的二值化处理函数threshold()详解
联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
Swagger突然发癫
Some thoughts on whether the judgment point is located in the contour
随机推荐
TCP两次挥手,你见过吗?那四次握手呢?
The 300th weekly match of leetcode (20220703)
牛客小白月赛7 E Applese的超能力
Add namespace declaration
如何使用Async-Awati异步任務處理代替BackgroundWorker?
Generate XML elements
The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
2014 Hefei 31st youth informatics Olympic Games (primary school group) test questions
在线文本行固定长度填充工具
Jetpack Compose 教程
Pytorch学习(四)
Guys, for help, I use MySQL CDC 2.2.1 (Flink 1.14.5) to write Kafka and set
26. Delete the duplicate item C solution in the ordered array
Use canal and rocketmq to listen to MySQL binlog logs
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
在线SQL转Excel(xls/xlsx)工具
西门子HMI下载时提示缺少面板映像解决方案
Shell programming core technology "three"
1008 Elevator(20 分)(PAT甲级)
The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.