码迷,mamicode.com
首页 > 其他好文 > 详细

HW6.15

时间:2016-08-26 13:42:07      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 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 }

 

HW6.15

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5809901.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!