Home > Mobile >  How do I fill a matrix with 0 in Kotlin?
How do I fill a matrix with 0 in Kotlin?

Time:02-17

I need to fill an 8x8 matrix just with 0.

I know it is possible to do the following:

board = arrayOf(
            intArrayOf(0, 0, 0, 0, 0, 0, 0, 0),
            intArrayOf(0, 0, 0, 0, 0, 0, 0, 0),
            intArrayOf(0, 0, 0, 0, 0, 0, 0, 0),
            intArrayOf(0, 0, 0, 0, 0, 0, 0, 0),
            intArrayOf(0, 0, 0, 0, 0, 0, 0, 0),
            intArrayOf(0, 0, 0, 0, 0, 0, 0, 0),
            intArrayOf(0, 0, 0, 0, 0, 0, 0, 0),
            intArrayOf(0, 0, 0, 0, 0, 0, 0, 0),
        )

This time is just an 8x8 so it's not too much work, but what if I have an 200x200 matrix, what should I do?

CodePudding user response:

val board = Array(8) { IntArray(8) { 0 } }
  • Related