标签:
1 import java.util.Scanner; 2 import java.util.ArrayList; 3 4 public class Solution 5 { 6 public static void main(String[] args) 7 { 8 Scanner input = new Scanner(System.in); 9 System.out.print("Enter 10 numbers: "); 10 11 int[] number = new int[10]; 12 13 for(int i = 0; i < 10; i++) 14 number[i] = input.nextInt(); 15 16 input.close(); 17 18 int noRepetitionArray[] = eliminateDuplicates(number); 19 for(int i: noRepetitionArray) 20 System.out.print(i + " "); 21 } 22 23 public static int[] eliminateDuplicates(int[] array) 24 { 25 ArrayList<Integer> list = new ArrayList<>(); 26 for(int i = 0; i < array.length; i++) 27 if(!list.contains(array[i])) 28 list.add(array[i]); 29 int[] number = new int[list.size()]; 30 for(int i = 0; i < number.length; i++) 31 number[i] = list.get(i); 32 return number; 33 } 34 }
标签:
原文地址:http://www.cnblogs.com/wood-python/p/5809901.html