So, i am writing a program that analyzes an entire array and displays the repeated values as well as the unique values:
int dupe = 0;
int[] range = {1, 1, 2, 2, 2, 3, 3, 3, 4, 5, 6, 6};
for (int i = 0; i < range.length; i++) {
for (int j = i + 1; j < range.length; j++) {
if (range[i] == range[j]) {
dup = range[j];
System.out.println(dup);
}
}
}
The above code outputs the repeated values correctly but when the value repeats three or more times, it outputs that value many times instead of just once
1
2
2
2
3
3
3
6
How can i fix this?
For the unique value part of the program, i don't know where to start.
Thanks!
EDIT: The only Arrays class methods i can use are: binarySearch, copyOf, equals, fill, sort, and toString
I need to write my own implementation - not to use Set, HashSet etc. Or any other tools such as iterators