Scala

Program to print only duplicate elements in an Integer Array using Scala

Write a Program to print only duplicate elements in an Integer Array?

Logic: Loop through each element of Array and Compare it with other elements.

[code lang=”scala”]object PrintDuplicates{
def main(args: Array[String]) {
for (i <- 0 until inputarray.length){
for(j <- i+1 until inputarray.length){
if(inputarray(i)==inputarray(j)){
println(inputarray(i))
}
}
}
}
}[/code]

Share This Post

An Ambivert, music lover, enthusiast, artist, designer, coder, gamer, content writer. He is Professional Software Developer with hands-on experience in Spark, Kafka, Scala, Python, Hadoop, Hive, Sqoop, Pig, php, html,css. Know more about him at www.24tutorials.com/sai

Lost Password

Register

24 Tutorials