Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EliminateDups {
  4. public static void main(String[] args) {
  5. int[] myArray = new int[10];
  6. Scanner input = new Scanner(System.in);
  7. for (int i = 0; i < 10; i++) {
  8. myArray[i] = input.nextInt();
  9. }
  10. myArray = eliminateDuplicates(myArray);
  11. for (int i =0; i < myArray.length; i++) {
  12. System.out.print(myArray[i] + " ");
  13. }
  14. }
  15. public static int[] eliminateDuplicates(int[] list) {
  16. int dupes = 0;
  17. for (int i = 0; i < 10; i ++) {
  18. for (int j = i+1; j < 10; j++) {
  19. if (list[i] == list [j]) {
  20. list[i] = 0;
  21. dupes++;
  22. }
  23. }
  24. }
  25. for (int i =0; i < list.length; i++) {
  26. System.out.print(list[i] + " ");
  27. }
  28. System.out.println(" ");
  29.  
  30. int[] noDupes = new int[10-dupes];
  31. for (int i = 0, j = 0; i < noDupes.length; i++)
  32. System.out.println(list[i]);
  33. if (list[i] != 0) {
  34. System.out.print(list[i]);
  35. noDupes[j] = list[i];
  36. j++;
  37. }
  38. return(noDupes);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement