NutzCN Logo
短点 作业_a3742faa
发布于 3222天前 作者 明天会吹什么风 1502 次浏览 复制 上一个帖子 下一个帖子
标签:

查看完整内容

 *群里一共14人,平均每秒随机有一人发言,统计五分钟每人的发言次数
 ****************************************************************/
class SuiJiShu
{
	public static void main(String[] args)
	{
		int[] counter = new int[13];
		int j;
		
		for ( j = 0; j < 14; j ++)
		{
			counter[j] = 1;
		}
		
		outerloop: for (int i = 0; i < 300; i++)            //5 min == 300 s;
		{
			int num = (int)((Math.random())*13);            //以随机数的产生模拟发言
			
			switch (num)
			{
				case  0:
				    counter[0] ++;
					continue outerloop;
				case  1:
				    counter[1] ++;
					continue outerloop;
				case  2:
				    counter[2] ++;
					continue outerloop;
				case  3:
				    counter[3] ++;
					continue outerloop;
				case  4:
				    counter[4] ++;
					continue outerloop;
				case  5:
				    counter[5] ++;
					continue outerloop;
				case  6:
				    counter[6] ++;
					continue outerloop;
				case  7:
				    counter[7] ++;
					continue outerloop;
				case  8:
				    counter[8] ++;
					continue outerloop;
				case  9:
				    counter[9] ++;
					continue outerloop;
				case 10:
				    counter[10] ++;
					continue outerloop;
				case 11:
				    counter[11] ++;
					continue outerloop;
				case 12:
				    counter[12] ++;
					continue outerloop;
				case 13:
				    counter[13] ++;
					continue outerloop;
			}
			
			System.out.print(" " + counter[j]);
			//System.out.println("num is: " + num);
		}
	}
} 

1 回复
添加回复
请先登陆
回到顶部