public class K8 { public static void main(String[] args) { int [] nums = {1,2,3,2,5,3,7,3,8,2,4,9,3,2,6,4}; int count=0; for (int i = 1; i < 10; i++) { for (int j = 0; j < nums.length; j++) { if(nums[j]==i){ count++; } }System.out.println(count); count=0; //这个是什么意思。谢谢 } }}
10 回答
maybelater
TA贡献1条经验 获得超0个赞
public static void main(String[] args) { int [] nums = {1,2,3,2,5,3,7,3,8,2,4,9,3,2,6,4}; int count=0; for (int i = 1; i < 10; i++) { for (int j = 0; j < nums.length; j++) { if(nums[j]==i){ count++; } }System.out.println(i+" 出现 "+count+" 次"); count=0; } }
调整了一下输出语句,这样更容易理解吧。
copy to your eclipse.
噼喱啪啦
TA贡献392条经验 获得超170个赞
for (int i = 1; i < 10; i++) {
for (int j = 0; j < nums.length; j++) {
if(nums[j]==i){
count++;
}
}System.out.println(count);
count=0; //计算数组里面有多少个数等于i,变量i也要从1开始到10,所以每次count要归0
}
添加回答
举报
0/150
提交
取消