Skip to content

Instantly share code, notes, and snippets.

@rail-rate
Created August 15, 2019 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rail-rate/4ba66f6b3daf23c0b22dced18be45523 to your computer and use it in GitHub Desktop.
Save rail-rate/4ba66f6b3daf23c0b22dced18be45523 to your computer and use it in GitHub Desktop.
main外8
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