title: Excluding duplicate values in an array (Java)
body: <p>For an assignment I must read values from a file, and print them on the screen unless they are duplicate values. My approach was to create two arrays with the same values, then somehow compare them and if they are not equal, it would not print. Here is what I have:</p>
  
  <pre><code>import java.io.*;
  import java.util.Scanner;
  
  public class Set8_Prog4
  {
      public static void main (String[] args) throws IOException
      {
          FileReader i = new FileReader("Set8_Prog4 numbers.txt");
          Scanner j = new Scanner(i);
  
          int length = 0;
          while (j.hasNextInt())
          {
              length++;
          }
          int[] values = new int[length];
          int[] values2 = new int[length];
          int k = 0;
          while (j.hasNextInt())
          {
              values[k] = j.nextInt();
              k++;
          }
          k = 0;
          while (j.hasNextInt())
          {
              values2[k] = j.nextInt();
              k++;
          }
          k = 0;
          int m = 0;
          while (values[k] != values2[m] &amp;&amp; k &lt; values.length)
          {
              while (m &lt; values.length)
              {
                  m++;
              }
              System.out.println(values[k]);
              k++;
          }
          j.close();
      }
  }
  </code></pre>
  
  <p>It compiles, but you can probably tell it doesn't get the job done. I have been frying my brain trying to figure out how to get it to work. I could use some help. Oh and we can't use things like Array Lists, Hashsets, or anything like that. Just arrays.</p>
  
  <p>UPDATED CODE:</p>
  
  <pre><code>import java.io.*;
  import java.util.Scanner;
  
  public class Set8_Prog4
  {
      public static void main (String[] args) throws IOException
      {
          FileReader i = new FileReader("Set8_Prog4 numbers.txt");
          Scanner j = new Scanner(i);
  
          int length = 0;
          while (j.hasNextInt())
          {
              length++;
          }
          int[] values = new int[length];
          int[] values2 = new int[length];
          int k = 0;
          while (j.hasNextInt())
          {
              values[k] = j.nextInt();
              k++;
          }
          k = 0;
          while (j.hasNextInt())
          {
              values2[k] = j.nextInt();
              k++;
          }
          int m;
          for (k = values.length; k &gt;= 0; k--)
          {
              boolean found = false;
              for (m = 0; m &lt; values.length; m++)
              {
                  if ((values[k] == values2[m]) &amp;&amp; (k != m))
                  {
                      found = true;
                      continue;
                  }
                  if (!found)
                  {
                      System.out.println(values[k]);
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>I get nothing when I run it. No errors though.</p>