JAVA有30个0-9的数字分别统计0-9这10个数字分别出现了多少次?
展开全部
public class test {
public static void main(String[] args) {
int[] a = new int[30], b = new int[10];
for (int i = 0; i < a.length; i++) {
a[i] = (int) (Math.random() * 10); System.out.print(a[i]+",");
}
for (int i = 0; i < a.length; i++) {
b[a[i]]++;
}
System.out.println();
for (int i = 0; i < b.length; i++) {
System.out.println(i+"出现了"+b[i]+"次");
}
}
}
public static void main(String[] args) {
int[] a = new int[30], b = new int[10];
for (int i = 0; i < a.length; i++) {
a[i] = (int) (Math.random() * 10); System.out.print(a[i]+",");
}
for (int i = 0; i < a.length; i++) {
b[a[i]]++;
}
System.out.println();
for (int i = 0; i < b.length; i++) {
System.out.println(i+"出现了"+b[i]+"次");
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询