本文介绍了随机生成的数字列表中的频率计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从0-9生成了100个随机数,我应该计算每个数字出现了多少次.将其存储在10个整数数组中并对其进行计数.

I generated 100 random numbers from 0-9, I am supposed to count how many times each number appears. Storing it in an array of 10 integers and count it.

这是我到目前为止所拥有的,我无法弄清计数部分.

Here's what I have so far, I cant figure out the count part.

Random r = new Random();
int[] integers = new int[100];

for (int i=0; i<integers.length; i++)
{
  integers[i] = (r.nextInt(10)+0);
}

推荐答案

以下是一个线索:您需要采用 array index 代表要存储的数字和 value的方法等于该频率.

Here's a clue: You need to take the approach whereby the array index represents the number being stored, and the value of that array element equals the frequency.

祝你好运!

这篇关于随机生成的数字列表中的频率计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 09:44
查看更多