Kotlin Program to copy all elements of an array to another array
In this program, You will learn how to copy all elements of an array to another array in Kotlin.
List are: 2 3 4 5 2 3 4 5 9 10
Example: How to copy all elements of an array to another array in Kotlin.
import java.util.Scanner
fun main(args: Array<String>) {
val arr1 = IntArray(5)
val arr2 = IntArray(5)
val sc = Scanner(System.`in`)
print("Enter 5 elements:")
for (i in 0 until arr1.size) {
arr1[i] = sc.nextInt()
}
for (i in 0 until arr1.size) {
arr2[i]=arr1[i]
}
print("Second array list are:")
for(n in arr2){
print("$n ")
}
}
Output:
Enter 5 elements:10 20 30 40 50
Second array list are:10 20 30 40 50