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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started