当前位置:网站首页>kotlin 条件控制
kotlin 条件控制
2022-07-04 18:32: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 类似三元操作符
d = if (a > b) 20000 else 0
println("d: $d") // 20000
println("------")
// 3 IF 表达式的结果赋值给一个变量
val sum = if (a > b) {
1000000
} else {
0
}
println(sum) // 1000000
// 4 区间
val g = 13
if (g in 1..18) {
println("未成年")
} else if (g > 18) {
println("成年")
}
// 5 when表达式
// when 类似其他语言的 switch 操作符
val x = 38
when(x){
0, 1 -> println("刚刚出生")
in 1..18 -> println("未成年")
!in 20..28 -> println("未成年2")
else -> {
println("成年了")
}
}
}
边栏推荐
- Lm10 cosine wave homeopathic grid strategy
- HDU 1097 A hard puzzle
- Have you guys ever used CDC direct Mysql to Clickhouse
- Pytest 可视化测试报告之 Allure
- sqlserver的CDC第一次查询的能读取到数据,但后面增删改读取不到,是什么原因
- Stream stream
- Educational codeforces round 22 E. Army Creation
- HDU 1372 & POJ 2243 Knight Moves(广度优先搜索)
- 关于判断点是否位于轮廓内的一点思考
- SSL证书续费相关问题详解
猜你喜欢
随机推荐
Online text line fixed length fill tool
Is Guoyuan futures a regular platform? Is it safe to open an account in Guoyuan futures?
指定输出的字符集
升级智能开关,“零火版”、“单火”接线方式差异有多大?
C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
“只跑一趟”,小区装维任务主动推荐探索
Add namespace declaration
HDU 1097 A hard puzzle
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
sqlserver的CDC第一次查询的能读取到数据,但后面增删改读取不到,是什么原因
Shell programming core technology "four"
HDU 6440 2018中国大学生程序设计网络选拔赛
Educational Codeforces Round 22 E. Army Creation
Reflection (I)
牛客小白月赛7 E Applese的超能力
English语法_名词 - 使用
1006 Sign In and Sign Out(25 分)(PAT甲级)
Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
YOLOv5s-ShuffleNetV2









