1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Pachacha [2.7K]
3 years ago
12

write a program that generates 100 random integrs between 0 and 9 and displays the count for each number. (Hint: Use (int) (math

.random() * 10) to generate a random integer between 0 and 9. Use an array of ten integers, say counts, to store the counts for the number of 0's , 1's,....,9's.)
Computers and Technology
1 answer:
Nataly_w [17]3 years ago
8 0

Answer: The java program to generate 100 random numbers and count their occurrence is shown below.

import java.util.Random;

import java.util.*;

public class MyClass {

   public static void main(String args[]) {

     int[]count = new int[10];

// temporarily stores the randomly generated number

     int num;

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

     {

// initialize count of all digits from 0 to 9 to zero

           count[i] = 0;

     }

     for(int i=0; i<100; i++)

     {

// generates 100 random numbers or integers from 0 through 9

           num = (int) (Math.random() * 10);

           for(int j=0; j<10; j++)

           {

// compare each randomly generated number with digits from 0 to 9 and increment their count accordingly

               if(num == j)

                   count[j] = count[j]+1;

           }

     }

     System.out.println("The count of randomly generated numbers is shown below.");

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

     {

           System.out.println("Count of "+i+" is "+ count[i]);

     }

   }

}

OUTPUT

The count of randomly generated numbers is shown below.

Count of 0 is 10

Count of 1 is 8

Count of 2 is 13

Count of 3 is 10

Count of 4 is 9

Count of 5 is 13

Count of 6 is 7

Count of 7 is 11

Count of 8 is 9

Count of 9 is 10

Explanation: This program declares an integer array of size 10 and initializes it to 0.

Random numbers are generated as shown. The number is randomly generated in an outer for loop with executes 100 times for 100 numbers.

(int) (Math.random() * 10)

The package java.util.Math is imported to serve the purpose.

The above code generates random numbers which can be floating numbers. The integer part is extracted using (int).

This yields the digits from 0 through 9.

For every occurrence of digits from 0 to 9, the count of the index of the respective digit is incremented.

To serve this purpose, inner for loop is implemented. The variable used in this loop is compared with the random number and index of count incremented accordingly. The inner for loop runs 10 times at the maximum, in order to match random number with 0 through 9.

Lastly, the occurrence of every digit from 0 to 9 is displayed.

You might be interested in
What are the possible consequences of intentional virus setting?
natali 33 [55]

<u>The possible consequences of intentional virus setting:</u>

Virus is nothing but desktop or laptop or tablet OS has to do certain process as on its own which diverse other  to different process  such us stealing the data from desktop or laptop or tablet and making slow the performance of desktop and laptop  and tablet.

To avoid or protect the computer there are two type of antivirus.

  • On desktop or tablet or laptop. (It is called resident firewall).
  • Internet gateway. (It is called firewall)

So company create virus and to rectify they make money of that process.

To protect our desktop or laptop or tablet from virus we are protected with law. In case due to virus attacked our laptop or desktop or tablet Is effected we can fine the or sent to jail by law.

3 0
3 years ago
How do I type over Images (photo posted ​
Ber [7]
Oh a document, I do not believe that you have type on images, but if you were to type a text in a app called PicsArt and saved it and then put it onto the document over the picture it would work.
3 0
2 years ago
Read 2 more answers
Add the following numbers in abacus 2436+9214​
bazaltina [42]

Answer:

the answer is - 11,650

Explanation:

you study abacus too ?

4 0
2 years ago
Once Raul selects a technology solution, he has completed the process. <br> a. True<br> b. False
romanna [79]
The answer is true because choosing a technology solution is the last step
7 0
3 years ago
Read 2 more answers
To achieve balance—that is, to operate an information system that satisfies the user and the security professional—the security
marta [7]

the answer is True

there has to be a balance between security and the user experience

7 0
2 years ago
Other questions:
  • The ____ is a new feature in versions of microsoft office, starting with office 2007; it consists of tabs, which contain groups
    5·1 answer
  • You have installed a point-to-point connection using wireless bridges and Omni directional antennas between two buildings. The t
    9·1 answer
  • How do you increase the amount of data in a sampled Google Analytics report?
    8·1 answer
  • How can i take out a random (double) number in between 5.0 to 15.0 in c++?
    7·1 answer
  • Write a method that take an integer array as a parameter and returns the sum of positive odd numbers and sum of positive even nu
    13·1 answer
  • The _____ toolbar can be customized to the preferences of the user.
    7·1 answer
  • What are two constraints that continuous-media files have that conventional data files generally do not have?
    12·1 answer
  • What to do when you strip a screw
    10·2 answers
  • Name three recent advances that are influencing OS design.
    15·1 answer
  • Please create C program, the task is to implement a function edoublepowerx that has an input parameter x of floating-point value
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!