Question: //Trying to make Java program to put unique numbers in an array to different array and print. //Numbers entered in the file are sorted but
//Trying to make Java program to put unique numbers in an array to different array and print.
//Numbers entered in the file are sorted but have duplicates
public static void main(String[] args)
{ StdOut.print("File to read in: "); String filename = StdIn.readLine();
In infile = new In(filename); int[] numbers = infile.readAllInts();
int n = numUniquey.length; int [] numUniquey= add_element(n, numUniquey, ele); StdOut.println("These are the unique numbers " + numUniquey);
}
public static int[] add_element(int n,int[] a, int ele) { int lengthus= a.length; int numUnique= 0; int [] numUniquey= new int[lengthus-1]; for (int i=0; i < (lengthus); i++) { while( (i < lengthus -1) && a[i] == a[i+1]) { i++;
} numUnique++; numUniquey= add_element((lengthus-1), numUniquey, a[i]); } return numUniquey;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
