fork 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.  
  11. private static int[] removeDuplicates(int[] array) {
  12. int rdIndex = 1;
  13. int wrIndex = 1;
  14. while (rdIndex != array.length) {
  15. if (array[wrIndex-1] != array[rdIndex]) {
  16. array[wrIndex++] = array[rdIndex];
  17. }
  18. rdIndex++;
  19. }
  20. return Arrays.copyOf(array, wrIndex);
  21. }
  22.  
  23. public static void main (String[] args) throws java.lang.Exception
  24. {
  25.  
  26.  
  27. Random random = new Random();
  28. int array[]= new int[10];
  29. for (int i = 0; i < array.length; i++)
  30. {
  31. array[i] = random.nextInt(10)+ 1;
  32. }
  33. Arrays.sort(array);
  34. for (int i = 0; i < array.length; i++)
  35. {
  36. System.out.print(array[i] + " ");
  37. }
  38. System.out.println();
  39. array = removeDuplicates(array);
  40. for (int i = 0; i < array.length; i++)
  41. {
  42. System.out.print(array[i] + " ");
  43. }
  44.  
  45.  
  46. }
  47. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
3 3 4 4 4 5 6 7 8 9 
3 4 5 6 7 8 9