2019年4月21日日曜日

開発環境

Head First Kotlin: A Brain-Friendly Guide (Dawn Griffiths(著)、David Griffiths(著)、O'Reilly Media)のChapter 9(collections - Get Organized)、Pool Puzzle(283)の解答を求めてみる。

コード

fun main() {
    val term1 = "Array"
    val term2 = "List"
    val term3 = "Map"
    val term4 = "MutableList"
    val term5 = "MutableMap"
    val term6 = "MutableSet"
    val term7 = "Set"

    val def1 = "Holds values in no particular order."
    val def2 = "Holds key/value pairs."
    val def3 = "Holds values in a sequence."
    val def4 = "Can be updated."
    val def5 = "Can't be updated."
    val def6 = "Can be resized."
    val def7 = "Can't be resized."

    val glossary = mapOf(
        term4 to "$def3 $def4 $def6",
        term7 to "$def1 $def5 $def7",
        term1 to "$def3 $def4 $def7",
        term5 to "$def2 $def4 $def6",
        term2 to "$def3 $def5 $def7",
        term6 to "$def1 $def4 $def6",
        term3 to "$def2 $def5 $def7"
    )
    for ((key, value) in glossary) println("$key: $value")
}

入出力結果

MutableList: Holds values in a sequence. Can be updated. Can be resized.
Set: Holds values in no particular order. Can't be updated. Can't be resized.
Array: Holds values in a sequence. Can be updated. Can't be resized.
MutableMap: Holds key/value pairs. Can be updated. Can be resized.
List: Holds values in a sequence. Can't be updated. Can't be resized.
MutableSet: Holds values in no particular order. Can be updated. Can be resized.
Map: Holds key/value pairs. Can't be updated. Can't be resized.

Process finished with exit code 0

0 コメント:

コメントを投稿