java: Write a program that generates 100 random integers between 0 and 9, and then displays the number of occurrences of each number. Need to use arrays.

Write a program that generates 100 random integers between 0 and 9, and then displays the number of occurrences of each number. Need to use arrays. The program source code is as follows:
import java.util.Random; // The guide package for random numbers
public class Test2 {
public static void main (String [] args) {
int [] numCount = new int [10];
int [] nums = new int [100];
for (int i = 0; i <100; i ++) {
nums [i] = new Random (). nextInt (10);
} // Generate a random number from 0 to 9
for (int i: nums) {
numCount [i] ++;
} // Iterate through nums and receive with i, and do the sum of the number of occurrences of a number
for (int i = 0; i <10; i ++) {
System.out. println (i + "appeared:" + numCount [i] + "time.");
} // output
}
}

operation result:
Insert picture description here

This article is original, please indicate the source.
If it helps you, please give me a thumbs up!

Published 9 original articles · won 9 · visited 2166

Guess you like

Origin blog.csdn.net/grandniu/article/details/105134817