Kotlin Program using an array with a loop

In this program, You will learn how to implement an array with a loop in Kotlin.

Array list is: 2 3 4 5 6

Example: How to implement an array with a loop in Kotlin.

import java.util.Scanner

fun main(args: Array<String>) {

    var arr = IntArray(100)
    var n: Int
    val sc = Scanner(System.`in`)

    print("Enter size of an array:")
    n = sc.nextInt()

    print("Enter $n elements :")
    for (i in 0 until n) {
        arr[i] = sc.nextInt()

    for (i in 0 until n) {
        println("item :${arr[i]} ")


Enter size of an array:5
Enter 5 elements :10 20 30 40 50
item :10 
item :20 
item :30 
item :40 
item :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.