Here is the problem I am working on: "Write a method that returns a new array by eliminating the duplicate values in the array using the following method header:
public static int[] eliminateDuplicates(int[] list)
Write a test program that read in ten integers, invokes the method and displays the result."
Here is the code I have:
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] list = new int[10];
System.out.print("Enter ten numbers:");
for (int i = 0; i < list.length; i++) {
list[i] = input.nextInt();
}
System.out.print("The distinct numbers are: ");
for(int i = 0; i < 10; i++){
if( list[i] != -1){
System.out.print(eliminateDuplicates(list));
}
}
}
public static int[] eliminateDuplicates(int[] list) {
for(int i = 0; i < 10; i++){
for(int j = i + 1; j < 10; j++){
if (list[i] == list[j]){
list[i]= -1;
}
}
}
return list;
} }
My issue is my output is really strange, this is what I'm getting "[I@55f96302[I@55f96302[I@55f96302[I@55f96302[I@55f96302[I@55f96302[I@55f96302"
Can anyone tell me where I'm going wrong? Or a suggestion of where to start fixing it? I'm still a beginner, so I haven't learned a whole lot (like hashsets or anything).
You have my many thanks