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]
4 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]4 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
The amount of pressure a power source creates to move electrons. *
Ksju [112]

Answer:

go to gogle

Explanation:

do it it giv ansewr better xd

3 0
3 years ago
A _____________ is used to make a deep copy of an object.
lesya [120]
The answer is a 3D Printer
3 0
4 years ago
Let A be an array of n numbers. Recall that a pair of indices i, j is said to be under an inversion if A[i] &gt; A[j] and i &lt;
AysviL [449]

Answer:

Check the explanation

Explanation:

#include <stdio.h>

int inversions(int a[], int low, int high)

{

int mid= (high+low)/2;

if(low>=high)return 0 ;

else

{

int l= inversions(a,low,mid);

int r=inversions(a,mid+1,high);

int total= 0 ;

for(int i = low;i<=mid;i++)

{

for(int j=mid+1;j<=high;j++)

if(a[i]>a[j])total++;

}

return total+ l+r ;

}

}

int main() {

int a[]={5,4,3,2,1};

printf("%d",inversions(a,0,4));

  return 0;

}

Check the output in the below attached image.

5 0
3 years ago
The google android mobile operating system is a proprietary system, for use on only approved devices.​
balandron [24]
I would choose b. False
7 0
3 years ago
Boolean logic deals with statements having one of _____ values.
Alexxandr [17]

Answer:

2 values

Explanation:

boolean statements can only be True or False

6 0
3 years ago
Other questions:
  • An online company wants to conduct real-time sentiment analysis about its products from its social media channels using SQL.
    12·1 answer
  • A(n) __________ is a recording of a motion picture, or television program for playing through a television.
    8·2 answers
  • The use of electronic media, information, and communication technologies to deliver instruction where students are not required
    8·1 answer
  • The private field, which is known as the property‘s __________, holds any data that is assigned to the property.a. private datab.
    9·1 answer
  • A network administrator was testing an IPS device by releasing multiple packets into the network. The administrator examined the
    13·2 answers
  • Write a program that dynamically allocates an array large enough to hold a user-defined number of test scores. Once all the scor
    5·1 answer
  • Q1 To remove filter
    15·2 answers
  • Guys help me, to get 25 examples of computer software​
    8·1 answer
  • Original documents or objects used during Internet research are known as
    8·2 answers
  • Digital Print Project
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!