countDuplicates
Language/Type:
Author:
Java arrays traversals
Marty Stepp (on 2016/08/27)
Write a method named countDuplicates that accepts an array of integers as a parameter and that returns the
number of duplicate values in the array. A duplicate value is a value that also occurs earlier in the array. For example, if an
array named a contains [1, 4, 2, 4, 7, 1, 1, 9, 2, 3, 4, 1], then the call of countDuplicates(a) should
return 6 because there are three duplicates of the value 1, one duplicate of the value 2, and two duplicates of the value 4.
Constraints: The array could be empty or could contain only a single element; in such cases, your method should return 0.
Do not modify the contents of the array.
Type your Java solution code here:
Java solution code goes here
This is a method exercise. Write a Java method as described. Do not write a complete program or class; just the method(s) above.
You must log in before you can solve this problem.