title: Java: Removing duplicates from a user inputted integer array
body: <p>Im trying to remove duplicates from a user inputted array using java and am getting an error for a duplicate variable, here is what i have so far:</p>
  
  <pre><code>public class sortedArray {
  
    static int alter(int array[], int n) {
      if (n == 0 || n == 1)
        return n;
      int[] arr = new int[n];
      int r = 0;
      for (int i = 0; i &lt; n - 1; i++)
        if (array[i] != array[i + 1])
          arr[r++] = array[i];
      arr[r++] = array[n - 1];
      for (int i = 0; i &lt; r; i++)
        array[i] = arr[i];
      return r;
    }
  
    public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      int[] array = new int[49];
      int n = array.length;
  
      System.out.print("enter some integers (enter -9999 to stop): ");
      for (int i = 0; i &lt; array.length; i++) {
        array[i] = input.nextInt();
        if (array[i] == -9999) {
          break;
        }
        n = alter(array, n);
        for (int i = 0; i &lt; n; i++) //getting error here on the i
          System.out.print(array[i] + " ");
      }
    }
  }
  </code></pre>
  
  <p>Any help would be appreciated.</p>