您的位置:首页 > 其它

求一个数组中各数字出现的次数

2011-11-29 20:53 155 查看
import java.util.Arrays;

public class FindMostNumber {
static int[] a=new int[]{1,9,2,3,1,3,5};
public static void main(String[] args) {
findMost();
}

public static void  findMost(){
Arrays.sort(a);
int len = a.length;
/* b记录出现的数字,c记录数字出现的次数 **/
int[] b = new int[len];
int[] c = new int[len];
/* m表示数组b、c的下标, n 表示数组a的下标 **/
int m=0;
int n=0;
for(int j=0;j<len;j++){
if(a
==a[j]){
b[m]=a
;
c[m]++;
}else{
m++;
n=j;
j--;
}
}
display(a);
display(b);
display(c);
}

public static void display(int[] a){
for(int i:a){
System.out.print(i+", ");
}
System.out.println();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐