I have a question about returning an array from one method back to main. It is seriously starting to annoy me and I cannot wrap my brain around this. It seems as if even though I have changed the array in my method, when I go to display it in main it displays the old array. I'm trying to remove the duplicate numbers in my array and I know it works because I have stepped through it in the debugger yet after I return it and go back to main, it displays the whole array again! I know it must be something easy that I am missing here. Can someone please point me in the right direction? Here is my code...
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] numbers = new int[10];
System.out.print("Enter 10 numbers: ");
for (int x = 0; x < numbers.length; ++x)
numbers[x] = input.nextInt();
eliminateDuplicates(numbers);
for (int y = 0; y < numbers.length; ++y)
System.out.print(numbers[y] + " ");
}
public static int[] eliminateDuplicates(int[] numbers) {
int[] temp = new int[numbers.length];
int size = 0;
boolean found = false;
for (int x = 0; x < numbers.length; ++x) {
for (int y = 0; y < temp.length && !found; ++y) {
if (numbers[x] == temp[y])
found = true;
}
if (!found) {
temp[size] = numbers[x];
size++;
}
found = false;
}
int[] result = new int[size];
for (int z = 0; z < result.length; ++z)
result[z] = temp[z];
return result;
}
}