This commit is contained in:
parent
f3402dc2d7
commit
490199fd8a
|
@ -32,8 +32,8 @@ fun main(array: Array<String>) {
|
||||||
println(c)
|
println(c)
|
||||||
|
|
||||||
// 返回最大值
|
// 返回最大值
|
||||||
println(BasicSyntax(1.0,2.0).maxOf(1, 2))
|
println(BasicSyntax(1.0, 2.0).maxOf(1, 2))
|
||||||
println(BasicSyntax(1.0,2.0).maxOf2(1, 2))
|
println(BasicSyntax(1.0, 2.0).maxOf2(1, 2))
|
||||||
println(maxOf3(1, 2))
|
println(maxOf3(1, 2))
|
||||||
|
|
||||||
// 循环
|
// 循环
|
||||||
|
@ -44,6 +44,43 @@ fun main(array: Array<String>) {
|
||||||
for (index in items.indices) {
|
for (index in items.indices) {
|
||||||
println(index)
|
println(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 有多少元素
|
||||||
|
val readOnlyShapes = mutableListOf("triangle", "square", "circle")
|
||||||
|
println("readOnlyShapes有:${readOnlyShapes.count()}个元素")
|
||||||
|
println("triangle" in readOnlyShapes)
|
||||||
|
// 添加元素
|
||||||
|
readOnlyShapes.add("YYY")
|
||||||
|
println(readOnlyShapes)
|
||||||
|
// 移出元素
|
||||||
|
readOnlyShapes.remove("triangle")
|
||||||
|
println(readOnlyShapes)
|
||||||
|
|
||||||
|
// Set相关操作
|
||||||
|
val readOnlyFruit = setOf("apple", "banana", "cherry", "cherry")
|
||||||
|
val mutableSetOf = mutableSetOf(readOnlyFruit)
|
||||||
|
println(readOnlyFruit)
|
||||||
|
println(mutableSetOf)
|
||||||
|
println("This set has ${readOnlyFruit.count()} items")
|
||||||
|
|
||||||
|
|
||||||
|
// map 操作
|
||||||
|
val readOnlyJuiceMenu = mapOf("apple" to 100, "kiwi" to 190, "orange" to 100)
|
||||||
|
println(readOnlyJuiceMenu)
|
||||||
|
// {apple=100, kiwi=190, orange=100}
|
||||||
|
|
||||||
|
// Mutable map with explicit type declaration
|
||||||
|
val juiceMenu: MutableMap<String, Int> = mutableMapOf("apple" to 100, "kiwi" to 190, "orange" to 100)
|
||||||
|
println(juiceMenu)
|
||||||
|
|
||||||
|
val SUPPORTED = setOf("HTTP", "HTTPS", "FTP")
|
||||||
|
val requested = "smtp"
|
||||||
|
val isSupported = requested.uppercase() in SUPPORTED // Write your code here
|
||||||
|
println("Support for $requested: $isSupported")
|
||||||
|
|
||||||
|
val number2word = mapOf(1 to "one", 2 to "tow") // Write your code here
|
||||||
|
val n = 2
|
||||||
|
println("$n is spelt as '${number2word[2]}'")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sum(a: Int, b: Int): Int {
|
fun sum(a: Int, b: Int): Int {
|
||||||
|
@ -76,4 +113,5 @@ class BasicSyntax(height: Double, length: Double) {
|
||||||
and ends here. */
|
and ends here. */
|
||||||
|
|
||||||
|
|
||||||
fun maxOf3(a:Int,b:Int)=if (a>b)a else b
|
fun maxOf3(a: Int, b: Int) = if (a > b) a else b
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue