Hey Guys Im working on an assignment dealing with arrays. I have to Delete the duplicates in the array and re-display the array with the duplicates deleted. I Have code that I written up that is able to step throgh the process and will display the duplicated elements in the array. I woas wondering if i was missing a step or i was missing another for loop or how would i go about doing this. Havent coded java in a few years, but any ways here is the no dups code:
public void NOdups()
{
//Declare a constant long value as the "null" value
for (int j = 0; j<nElems; j++) //Declare outer and inner loop indices
{ //For each element starting at the
beginning of the array and up to
the 2nd-last-of-element
for(int k = j+1; k<nElems; k++) //For each element starting at the
beginning of the array and
up to the 2nd-last-of-element
{
if(j == k) //If the element at the outer index = the element at the innner index
{
break;
}
else if (a[k] == a[j]) //The element at the inner index gets the "null" value
{
nElems--;
}
}//end k loop
}//end j loop
} //end NOdups
and then here is the is the class:
class HighArrayApp
{
public static void main(String[] args)
{
int maxSize = 100; // array size
HighArray arr; // reference to array
arr = new HighArray(maxSize); // create the array
arr.insert(17); // insert 10 items
arr.insert(99);
arr.insert(44);
arr.insert(55);
arr.insert(17);
arr.insert(17);
arr.insert(11);
arr.insert(00);
arr.insert(66);
arr.insert(33);
arr.getMax(); //displays Max Number of the Array
arr.display(); // display items
int searchKey = 35; // search for item
if( arr.find(searchKey) )
System.out.println("Found " + searchKey);
else
System.out.println("Can't find " + searchKey);
arr.delete(00); // delete 3 items
arr.delete(55);
arr.delete(99);
arr.getMax(); //Displays max Number after deleting 3 arrays
arr.display();
arr.NOdups();
arr.display();
} // end main()
} // end class HighArrayApp
When the Project is run i get this output:
Max Number in Current Array: 99
17 99 44 55 17 17 11 0 66 33
Can't find 35
Max Number in Current Array: 66
17 44 17 17 11 66 33
17 44 17 17
BUILD SUCCESSFUL (total time: 0 seconds)
(Clarification:)I need it to not display the duplicates but display the left over array and I have the Display() method all set
would really appreciate the help