Created
August 15, 2019 08:45
-
-
Save rail-rate/4ba66f6b3daf23c0b22dced18be45523 to your computer and use it in GitHub Desktop.
main外8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
printShow(5, 10) //2つの値の場合 | |
printShow(1, 2, 3) //3つの値の場合 | |
printShow(3, 3, 3, 3) //4つの値の場合 | |
} | |
fun printShow(vararg counts : Int){ //varargを使ってるので値の数に左右されず1つ用意すればOK | |
var result = 0 //ここで足し算用の変数を用意 | |
for(x in counts) result += x //for文で足していく | |
println(result) //結果を表示。値がいくつでも正しく表示されている。 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment