Ask Question
30 August, 17:06

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.

0
Answers (1)
  1. 30 August, 18:22
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers