From 307beb4274bc96877834368b7de9b1635bb4e216 Mon Sep 17 00:00:00 2001 From: luming Date: Tue, 29 Jun 2021 11:27:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/basic/Choice.kt | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/basic/Choice.kt diff --git a/src/basic/Choice.kt b/src/basic/Choice.kt new file mode 100644 index 0000000..24a4f36 --- /dev/null +++ b/src/basic/Choice.kt @@ -0,0 +1,47 @@ +package basic + +/** + * 选择语句 + */ + +fun main(args: Array) { + + // if语句 + var a: Int = 51 + var b: Int = 6 + if (a < b) { + println("ab") + } + + // 三元运算 + var c: Int = 0 + c = if (a > b) a else b + println(c) + + // else if + if (a > b) { + println("a>b") + } else if (a > b) { + println("a println(1) + 2 -> println(2) + 3, 4, 5, 6, 7 -> println("3..7") + else -> { + println("other1") + println("other2") + } + } + + when { + d == e -> println("d == e") + else -> println("else") + } +} \ No newline at end of file