0

I have an problem I am trying to solve, I need to use an algorithm to find the unqiue elements in a list, and print those along with the running time of the function to a csv file. I cannot figure out how to print it to a csv file or text file, I have tried printwriter but I do not get the correct output. Any info is greatly appreciated. Here is the code:

package uniqueelements.java;

    public class uniqueElements {

        public static void main(String[] args){

            int[] arr = {1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 1};

            uniqueElement(arr);

        }

        public static void uniqueElement(int[] a){
                long tStart = System.currentTimeMillis();
                for(int i = 0; i < a.length; i ++){
                    boolean isUnique = false;

                    for(int j = 0; j < i; j++){
                        if(a[i] == a[j]){
                            isUnique = true;
                            break;
                    }

                } if(!isUnique){
                    System.out.println(a[i] + " ");
                    }
            }
               long tEnd = System.currentTimeMillis();
               long total = (tEnd - tStart);

               System.out.println(total + "." + total/1000000);
        }
    }
Bellal Hossain
  • 150
  • 1
  • 7

0 Answers0