@Test
// int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
// 求出上面数组中0-9分别出现的次数
// 双重for循环
public void test3() {
int[] scores = {0, 0, 1, 2, 3, 5, 4, 5, 2, 8, 7, 6, 9, 5, 4, 8, 3, 1, 0, 2, 4, 8, 7, 9, 5, 2, 1, 2, 3, 9};
int count = 0;
for (int i = 0; i <= 9; i++) {
for (int j = 0; j < scores.length - 1; j++) {
int num = scores[j];
if (i == num) {
count++;
}
}
System.out.println(i + "出现的次数为:" + count);
count = 0;
}
}
求出整型数组中每一个元素出现的次数
最新推荐文章于 2022-04-07 16:39:27 发布