How to create a fixed size IntArray and initializing the array later in Kotlin?

Viewed 15358

I can't figure out a way to add values to an array in Kotlin .

I want to get values from user and add them to the array.

val arr = arrayOf<Int>()

or

var arr = intArrayOf()

In Java I would do something like this:

Scanner ob = new Scanner(System.in);
int arr[] = new int[5];
for (int i = 0; i < arr.length; i++) {
   arr[i]=ob.nextInt();
}

How can I do the same in Kotlin?

2 Answers
Related