Ask Question
7 June, 22:14

Write a Java program to generate 200 random integers in the range of 0 and 999 (both inclusive). Then find the appearance frequency of each digit (0-9) in these numbers, and print a frequency histogram.

+3
Answers (1)
  1. 8 June, 02:00
    0
    import java. util. Random;

    public class ArrayBar {

    public static void main (String[] args) {

    int arr[] = new int[10];

    Random r = new Random ();

    int n = 0;

    for (int i = 0; i < 200; i++) {

    n = r. nextInt (1000);

    while (n > 0) {

    arr[n % 10]++;

    n = n / 10;

    }

    }

    for (int i = 0; i < 10; i++) {

    System. out. print (i + " (" + arr[i] + ") : ");

    for (int j = 0; j < arr[i]; j++) {

    System. out. print ("*");

    }

    System. out. println ();

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a Java program to generate 200 random integers in the range of 0 and 999 (both inclusive). Then find the appearance frequency of each ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers