開発環境
- macOS Mojave - Apple (OS)
- Windows 10 Pro (OS)
- IntelliJ IDEA CE(Community Edition) (IDE(統合開発環境))
- Kotlin (プログラミング言語)
Head First Kotlin: A Brain-Friendly Guide (Dawn Griffiths(著)、David Griffiths(著)、O'Reilly Media)のChapter 3(functions - Getting Out of Main)、Code Magnets(67)の解答を求めてみる。
コード
// kotlinのrandomを利用 fun getGameChoice(optionsParam: Array<String>) = optionsParam[kotlin.random.Random.nextInt(optionsParam.size)] fun main() { val options = arrayOf("Rock", "Paper", "Scissors") var x = 0 while (x < 10) { println(getGameChoice(options)) x += 1 } }
入出力結果
Rock Rock Paper Rock Scissors Paper Scissors Paper Paper Scissors Process finished with exit code 0
0 コメント:
コメントを投稿