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 

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.