Arrays: Duplicate

Screen Shot 2014-12-07 at 12.13.44 PM

Classwork/Homework:
Write a program, Duplicate_YI.java to find a duplicate. Given an array of N elements with each element between 1 and N, write an algorithm to determine whether there are any duplicates. You do not need to preserve the contents of the given array, but do not use an extra array.

  • Create an array with 50 random integer numbers between 1 and 50 inclusive.
  • Print the array in 10 rows by 5 columns. Use printf” to keep the columns aligned.
  • Print all the duplicate values and their index. Format: value, index 1, index 2 … per line.
  • Print the total number of duplicates as the last message in your output.

duplicates