To create a Two Dimensional Array in Kotlin, you can use the Array constructor with the specified dimensions.
In this example,
matrix
with dimensions 3x3.fun main() {
val matrix = Array(3) { IntArray(3) }
for (row in matrix.indices) {
for (col in matrix[row].indices) {
matrix[row][col] = row + col
}
}
println(matrix.contentDeepToString())
}
[[0, 1, 2], [1, 2, 3], [2, 3, 4]]
In this tutorial, we learned How to create a Two Dimensional Array in Kotlin language with well detailed examples.