프로그래밍/Kotlin
[Kotlin] 배열에서 초기화
DwEnn
2018. 8. 10. 18:47
728x90
반응형
배열에서 초기화
val arr = arrayOfNulls<Int>(size)
for (i in arr)
i = sc.nextInt()
Val cannot be reassigned
에러가 뜬다
이유는 위 코드는 자바에서
for (final int i : array ) { .. }
와 같기 때문이란다
그래서 이와 같이 바꾸어준다
for (i in arr.indicies)
arr[i] = sc.nextInt()
+Reference
반응형