- <p>/*
- 获取数组中不同元素出现的个数
- */
- class GetCount
- {
- public static void main(String[] args)
- {
- int [] arr={2,3,7,7,8,8,7,3,4,5,4,2,3,3,5};
-
- getCount(arr);
- }
- public static void getCount(int [] arr)
- {
- //遍历数组
- // StringBuffer sb=new StringBuffer();
-
- System.out.println("数组的长度为:"+arr.length);
- int l=arr.length;
- // boolean flag=false;
- for (int a=0;a<arr.length ;a++ )
- {
- // boolean flag=false;
- int count=0;
- for (int b=0;b<arr.length ;b++ )
- {
-
- if(arr[a]==arr[b])
- {
- count++;
- // flag=true;
-
-
- }
- }
- System.out.println(arr[a]+"出现了:"+count+"次");
-
- }
- // System.out.println("l="+l);
- }
- }</p><p>
- //想获取数组中各个元素出现的次数,该如何更改,</p>
复制代码
|
|