Ask 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 digit (0-9) in these numbers, and print a frequency histogram.

+3
Answers (1)
  1. 5 April, 08: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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers