当前位置:网站首页>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 ")
}
}
}
边栏推荐
- Shell programming core technology "three"
- 92. (cesium chapter) cesium building layering
- . Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
- Pytorch学习(四)
- English grammar_ Noun - use
- JVM系列之对象的创建
- BCG 使用之CBCGPProgressDlgCtrl进度条使用
- 【毕业季】绿蚁新醅酒,红泥小火炉。晚来天欲雪,能饮一杯无?
- MySQL数据库基本操作-DDL | 黑马程序员
- Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
猜你喜欢

Hough transform Hough transform principle

FPGA timing constraint sharing 01_ Brief description of the four steps

Opencv functions and methods related to binary threshold processing are summarized for comparison and use

Introduction to polyfit software

JVM系列之对象的创建

node_ Exporter deployment

abc229 总结(区间最长连续字符 图的联通分量计数)

Stream流

TCP waves twice, have you seen it? What about four handshakes?

【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
随机推荐
联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
1008 elevator (20 points) (PAT class a)
HMM隐马尔可夫模型最详细讲解与代码实现
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
“只跑一趟”,小区装维任务主动推荐探索
添加命名空间声明
长城证券开户安全吗 买股票怎么开户
西门子HMI下载时提示缺少面板映像解决方案
Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
如何使用Async-Awati异步任務處理代替BackgroundWorker?
92. (cesium chapter) cesium building layering
Niuke Xiaobai month race 7 F question
HDU 6440 2018 Chinese college student program design network competition
Educational Codeforces Round 22 E. Army Creation
1002. A+B for Polynomials (25)(PAT甲级)
Euler function
kotlin 条件控制
勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
数据集划分
Swagger突然发癫