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
Pete would like to respond only to users within his organization with an automatic reply. He is configuring the automatic respon
Ahat [919]

Answer:

megan pete

Explanation:lol just  had to

4 0
3 years ago
Why is spyware more dangerous than adware
steposvetlana [31]

To find out how spyware is more dangerous, we must know what each term mean.

Adware is a <em>software that automatically displays advertising material usually on a site that a user goes to</em>.

Spyware is a <em>unwanted software that steals your internet usage data and personal information</em>.

So while Adware can be extremely annoying, it is not as potentially harmful as Spyware, which can steal your personal information and potentially ruin your life.

~

7 0
3 years ago
How do i divid 521 to the nearest tenth
Softa [21]

Answer:

520

Explanation:

take 521 round that to the nearest 10th and thats 520

8 0
3 years ago
Read 2 more answers
In which part of a professional email should you try to be brief, but highly descriptive?
Marta_Voda [28]
The answer is the subject line.

Hope this helps xox :)
3 0
3 years ago
These are the records and traces an individual leaves behind as they use the internet
Roman55 [17]

Answer:

Option D. Digital footprints

Explanation:

<u>Digital footprint is all the stuff you leave behind as you use the Internet.</u>

4 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following operations would best allow you to place 3D building models at their proper height on the terrain (e.g.,
    8·1 answer
  • When listing columns in the select list, what should you use to separate the columns?
    6·1 answer
  • ICT excel data homework
    10·1 answer
  • The numeric keys on the keyboard are sometimes called the ten keypad. true false
    9·2 answers
  • Software that translates the sound of human voice into text is called:________.
    14·1 answer
  • Mac or PC (need opinions please)<br><br> Why did you choose Mac/PC?
    10·2 answers
  • How would you reduce or minimize the size of a "file"?
    5·1 answer
  • What is the output?
    5·1 answer
  • You cannot then move and resize the control on the form as desired with your mouse TRUE OR FALSE​
    6·2 answers
  • Which Windows registry hive stores information about object linking and embedding (OLE) registrations
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!