当前位置:网站首页>Kotlin condition control
Kotlin condition control
2022-07-04 19:42:00 【AdleyTales】
fun main() {
val a = 12
val b = 5
var c: Int
var d: Int
if (a > b) {
c = 10000
} else {
c = 0
}
println("c: $c") // 10000
// 2 Similar to ternary operators
d = if (a > b) 20000 else 0
println("d: $d") // 20000
println("------")
// 3 IF The result of the expression is assigned to a variable
val sum = if (a > b) {
1000000
} else {
0
}
println(sum) // 1000000
// 4 Section
val g = 13
if (g in 1..18) {
println(" A minor ")
} else if (g > 18) {
println(" adult ")
}
// 5 when expression
// when Similar to other languages switch The operator
val x = 38
when(x){
0, 1 -> println(" Just born ")
in 1..18 -> println(" A minor ")
!in 20..28 -> println(" A minor 2")
else -> {
println(" Grown up ")
}
}
}
边栏推荐
猜你喜欢
Opencv functions and methods related to binary threshold processing are summarized for comparison and use
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
Stream stream
在线SQL转Excel(xls/xlsx)工具
Introduction to polyfit software
如何使用Async-Awati异步任务处理代替BackgroundWorker?
node_ Exporter deployment
Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)
Pytorch学习(四)
勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
随机推荐
92.(cesium篇)cesium楼栋分层
FPGA时序约束分享01_四大步骤简述
Cbcgpprogressdlg progress bar used by BCG
HMM隐马尔可夫模型最详细讲解与代码实现
Socket programming demo II
黑马程序员-软件测试--07阶段2-linux和数据库-09-24-linux命令学习步骤,通配符,绝对路径,相对路径,文件和目录常用命令,文件内容相关操作,查看日志文件,ping命令使用,
Siemens HMI download prompts lack of panel image solution
Chrome开发工具:VMxxx文件是什么鬼
安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
FTP, SFTP file transfer
HDU 1372 & POJ 2243 Knight moves (breadth first search)
Shell programming core technology II
做社交媒体营销应该注意些什么?Shopline卖家的成功秘笈在这里!
Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
Lm10 cosine wave homeopathic grid strategy
1011 World Cup Betting (20 分)(PAT甲级)
@transactional滥用导致数据源连接池耗尽问题
Shell 编程核心技术《四》
BCG 使用之新建向导效果
Functional interface