当前位置:网站首页>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)
}
边栏推荐
猜你喜欢

BCG 使用之CBCGPProgressDlg进度条使用

English grammar_ Noun - use

如何使用Async-Awati异步任務處理代替BackgroundWorker?

"Only one trip", active recommendation and exploration of community installation and maintenance tasks

“只跑一趟”,小区装维任务主动推荐探索

Introduction to polyfit software

node_exporter部署

LM10丨余弦波动顺势网格策略

Lm10 cosine wave homeopathic grid strategy

Euler function
随机推荐
欧拉函数
Specify the character set to output
HDU 1372 & POJ 2243 Knight Moves(广度优先搜索)
如何使用Async-Awati异步任务处理代替BackgroundWorker?
Mysql database basic operation -ddl | dark horse programmer
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
Pytest 可视化测试报告之 Allure
FTP, SFTP file transfer
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
偏移量函数及开窗函数
BCG 使用之CBCGPProgressDlgCtrl进度条使用
测试工程师如何“攻城”(上)
Euler function
YOLOv5s-ShuffleNetV2
Opencv functions and methods related to binary threshold processing are summarized for comparison and use
Stream stream
Online data migration scheme encountered in the project 1 - general idea sorting and technical sorting
HDU 1372 & POJ 2243 Knight moves (breadth first search)
Shell 编程核心技术《二》
联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点