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.

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))
              }
          }
      }
}
}

Share This Post

Avatar
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.saikumar.me

Lost Password

Register