当前位置:网站首页>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
- Several methods of online database migration
- Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
- Reflection (I)
- 线上数据库迁移的几种方法
- 指定输出的字符集
- 【毕业季】绿蚁新醅酒,红泥小火炉。晚来天欲雪,能饮一杯无?
- 偏移量函数及开窗函数
- FTP, SFTP file transfer
- HDU 1372 & POJ 2243 Knight moves (breadth first search)
猜你喜欢
欧拉函数
Niuke Xiaobai month race 7 who is the divine Archer
FPGA时序约束分享01_四大步骤简述
92. (cesium chapter) cesium building layering
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
Master the use of auto analyze in data warehouse
在线文本行固定长度填充工具
Oracle with as ORA-00903: invalid table name 多表报错
多表操作-外连接查询
Hough transform Hough transform principle
随机推荐
偏移量函数及开窗函数
1006 sign in and sign out (25 points) (PAT class a)
Functional interface
C语言-入门-基础-语法-流程控制(七)
指定输出的字符集
BCG 使用之CBCGPProgressDlgCtrl进度条使用
Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
黑马程序员-软件测试--09阶段2-linux和数据库-31-43修改文件权限字母发的说明,-查找链接修改文件,查找文件命令,链接文件,压缩解压方式,vi编辑器基本使用,
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
反射(一)
TCP两次挥手,你见过吗?那四次握手呢?
English语法_名词 - 使用
Educational Codeforces Round 22 E. Army Creation
Jetpack compose tutorial
1007 maximum subsequence sum (25 points) (PAT class a)
1003 emergency (25 points) (PAT class a)
[QNX Hypervisor 2.2用户手册]6.3.1 工厂页和控制页
Explicit random number
1011 World Cup betting (20 points) (pat a)