I have been given this question to do for a lab, which is to take in an array of ints from a user, then remove any duplicates and finally return the array in the same order. WE are restricted from using Hashsets and other set related ideas. There is no reason to order the list as it has to be in it's original order. Can anyone give me some tips or pointers in the right direction, I have been using some other quesitons already answered for some help. Here is what I have so far:
public class Q3C {
public static void main() {
System.out.println("Enter your numbers please: ");
Scanner numbers = new Scanner(System.in);
String nums = numbers.nextLine();
String[] parts = nums.split(" ");//
int[] n1 = new int[parts.length];//
for (int n = 0; n < parts.length; n++) {
n1[n] = Integer.parseInt(parts[n]);
}
}
I was thinking of creating another method, called removeDuplicates and sending the array to it which will then go through it, check each index for other duplicates and set all duplicates to the next index value. I just can not get that down though. Any help is much appreciated.