public class Work7 {
public static void main(String[] args) {
int[] arr = { 1, 5, 86, 5, 2, 4, 89, 5, 6, 2, 2, 2, 2, 1, 1, 1, 5, 1, 5, 15, 1 };
Method.foundnum(arr);
}
}
public static void foundnum(int[] arr) {
int count = 0;// 计数器
int max = arr[0];// 寻找数组里的最大值
for (int i = 0; i < arr.length; i++) {
if (max < arr[i]) {
max = arr[i];
}
}
System.out.println(max);
for (int i = 0; i <=max; i++) {
count=0;
for (int j = 0; j < arr.length; j++) {
if (i == arr[j]) {
count++;
}
}
if (count != 0) {
System.out.println(i + "出现的次数为:" + count);
}
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载