Write a kotlin program to find common elements between two arrays.

Write a program to identify common elements or numbers between two given arrays. You should not use any inbuilt methods are list to find common values.

Kotlin program to find common elements between two arrays


fun main(a: Array<String>) {
    val arr1 = intArrayOf(4, 7, 3, 9, 2)
    val arr2 = intArrayOf(3, 2, 12, 9, 40, 32, 4)
    for (i in arr1.indices) {
        for (j in arr2.indices) {
            if (arr1[i] == arr2[j]) {
                println(arr1[i])
            }
        }
    }
}


Output


4
3
9
2

 
Join My Facebook Group
Join Group
 

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions