调用方法中有形参为数组的函数:
fun checkIndex(index: Int, arr: Array<Int>) {
if(index in 0..arr.lastIndex) //arr.lastIndex返回的是数组的最后一位的下标
println("index in bounds")
else
println("index out of bounds")
}
checkIndex(5,arr = arrayOf(1,2,2,2))
输出结果:
index out of bounds
调用方法中有形参为数组的函数:
fun checkIndex(index: Int, arr: Array<Int>) {
if(index in 0..arr.lastIndex) //arr.lastIndex返回的是数组的最后一位的下标
println("index in bounds")
else
println("index out of bounds")
}
checkIndex(5,arr = arrayOf(1,2,2,2))
输出结果:
index out of bounds