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
Explain in detail what it means to synchronize computers and mobile devices. include at least two strategies for keeping your fi
alexdok [17]
Keeping track of common files by using a lot of computers and mobiles all through the day may be hard. A good example is when you synchronized your mobile and computer devices. If you check an email using your computer, it will also appear in your smartphone. This will be a lot easier to track your email through both of your devices than having not to be synced at all.
8 0
3 years ago
.- Una tienda de vestidos de fiesta, ofrece un descuento a las personas
elena55 [62]

ajaaaieisslslqlqlqqpqlkek3k2l2ll2llllww

4 0
3 years ago
Your traffic light changes to yellow as you approach an intersection. In most cases, what action should you take?
mamaluj [8]
Make every reasonable effort to stop.
6 0
3 years ago
Read 2 more answers
How to get out of compatibility mode in word?
fomenos
Compatibility mode is so older or different versions of word all look the same regardless of its current version.  So a lot of features you see in compatibility mode will be unavailable unless you upgrade.  If you upgrade though be sure to uninstall the older version first.  I hope this helped!!! Good Luck! :)
5 0
3 years ago
A(n) ____ is a web-based repository of information that anyone can access, contribute to, or modify.
IgorLugansk [536]

Wiki exists as a web-based repository of information that anyone can access, contribute to, or alter.

<h3>What is a wiki?</h3>

A wiki exists as a combined tool that authorizes students to donate and change one or more additional pages of course-connected materials. Wikis exist as collaborative in nature and promote community-building within a course. Essentially, a wiki exists as a web page with an open-editing system.

A wiki exists as a website or online resource that can be revised by multiple users. Some wikis, such as Wikipedia, exist publicly accessible. Others exist utilized by associations to manage data in-house, allowing teams to efficiently share knowledge and work together better effectively.

A wiki exists on a Web site that authorizes users to add and update content on the site utilizing their own Web browser. This exists created probable by Wiki software that operates on the Web server. Wikis finish up being driven mainly by a combined effort of the area visitors.

To learn more about wiki refer to:

brainly.com/question/25153373

#SPJ4

5 0
2 years ago
Other questions:
  • Recall that book ciphers do not necessarily require a full book to decode, but instead any written text, such as the Declaration
    6·1 answer
  • Which option can Jesse use to customize her company’s logo, name, address, and similar details in all her business documents?
    7·1 answer
  • Help me match these answers
    5·1 answer
  • The acceleration of a body is 3 metre per second square what does it mean​
    11·2 answers
  • Which of the following lists the proper order of the categories of the SOC system from general to specific?
    11·1 answer
  • What is a benefit of the rise in citizen journalism? Multiple answer choice below
    13·1 answer
  • use the internet to research the SYSTEM account. Why is it nessesary to include this account with full control on a directory
    13·1 answer
  • Write a method named isNumericPalindrome that accepts an integer parameter named num. If num is a palindrome the method must ret
    6·1 answer
  • What are acenders? What are decenders?
    10·2 answers
  • After turning on your computer ,it prompts you to type a password to continue the boot process. However ,you forgot the password
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!