fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static int[] tab = new int[]{1, 2, 3, 1, 2, 5, 1, 8, 3};
  11. static int nElems = tab.length;
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. int newElems = 0;
  15. for (int i = 0, x = nElems; i < x; i++) {
  16. int v = tab[i];
  17. boolean duplicate = false;
  18. for (int j = 0; j < newElems; j++) {
  19. duplicate |= v == tab[j];
  20. }
  21. if (!duplicate) {
  22. tab[newElems] = v;
  23. newElems++;
  24. }
  25. }
  26. nElems = newElems;
  27. System.out.println(Arrays.toString(Arrays.copyOf(tab, nElems)));
  28. }
  29. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
[1, 2, 3, 5, 8]