Java 生成随机数并记次数 | 您所在的位置:网站首页 › 怎样编写java程序输出随机数 › Java 生成随机数并记次数 |
生成随机数,统计每个数的次数
编写程序,生成0和9之间的50个随机整数,每行打印10个生成的随机数,然后显示每一个数出现的次数。(提示:使用(int)(Math.random()10)产生0到9之间的随机整数。使用一个名为counts的由10个整数构成的数组存放0,1,…,9的个数。) package com; public class Demo1_2 { public static void main(String[] args) { // TODO Auto-generated method stub int n = 0; int[] counts = new int[10]; System.out.println("生成50个随机数:"); for (int count = 0; count System.out.println(); } counts[element]++; } for (int i = 0 ; i |
CopyRight 2018-2019 实验室设备网 版权所有 |