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
An investor’s stock portfolio consists of four Exchange Traded Funds (SPY, QQQ, EEM, and VXX). Write a program that requests the
Allisa [31]

Answer:

The solution code is written in Python 3

  1. SPY = float(input("Enter SPY Amount: "))
  2. QQQ = float(input("Enter QQQ Amount: "))
  3. EEM = float(input("Enter EEM Amount: "))
  4. VXX = float(input("Enter VXX Amount: "))
  5. totalAmount = SPY + QQQ + EEM + VXX
  6. print("Total amount invested: $" + str(totalAmount))
  7. print("Percentage invested for SPY: " + str(SPY / totalAmount * 100) + "%")
  8. print("Percentage invested for QQQ: " + str(QQQ / totalAmount * 100) + "%")
  9. print("Percentage invested for EEM: " + str(EEM / totalAmount * 100) + "%")
  10. print("Percentage invested for VXX: " + str(VXX / totalAmount * 100) + "%")

Explanation:

Firstly, let's declare four variables, SPY, QQQ, EEM and VXX and use input() function to prompt user to input the amount invested in each fund (Line 1 - 4).

Next, sum up all the funds' amount and assign the total to totalAmount variable (Line 6).

Next display the total amount invested and the percentage invested for each fund using print function (Line 7 - 11). Please note the formula to calculate the percentage of investment is

(fund / totalAmount ) * 100

3 0
3 years ago
How do i cancel my subscription please help it doesnt say cancel anywhere todays the last day of my free trial help
Snowcat [4.5K]

Answer:

The answer is "turn off auto-renewal"

Explanation:

In the given question it is not defined, which type of subscription it is taking about. so, we assume, it is talking about software subscription and the cancellation of the software can be defined as follows:

  • The application base subscription provides a monthly or yearly service license scheme, which allows customers to purchase the cost per user.  
  • In general, users were also obligated to claim for there initial fee soon, which also enables it to use the software and by disabling the auto-renewal option we can cancel our subscription.
3 0
3 years ago
The objective is to work with your partner to fix the HTML bugs so that none of the code is pink. In general, how do I change HT
Elan Coil [88]

Answer:

Click inspect then go to change color

Explanation:

there you go have a nice day!

8 0
3 years ago
PLEASE HELP! WILL MARK AS BRAINLIEST!
insens350 [35]

Answer:

JavaScript can be implemented using JavaScript statements that are placed within the HTML tag

Explanation:

6 0
3 years ago
Read 2 more answers
What are the characteristics of computer. Explain any one​
Pachacha [2.7K]

Answer:

<h3>Your answer will be on the picture above..</h3>

Explanation:

Hope it helps you..

Y-your welcome in advance..

(;ŏ﹏ŏ)(ㆁωㆁ)

7 0
3 years ago
Read 2 more answers
Other questions:
  • Marie can now edit her photos, send them in emails, print them on a printer, and use them as wallpaper on her computer. This is
    9·2 answers
  • Part 2: students and courses, part 1  java review you may use an ide or a text editor, but i will test this by compiling and ru
    6·1 answer
  • A computer is a(n) ____ device, operating under the control of instructions stored in its own memory, that can accept data, proc
    9·1 answer
  • Select the correct answer. One of the functions of a data warehouse is to change table names to meaningful names. Which name is
    13·1 answer
  • Which tool is best used to test an electrical current for a power source?
    8·1 answer
  • An adjustable wrench's movable jaw is positioned <br> by​
    5·1 answer
  • InJava garbage collection is done by_______________JVM (Java VirtualMachine)ProgrammerBoth JVM (Java Virtual Machine)and Program
    9·1 answer
  • In Java. Write a program that creates an integer array with 50 random values, prompts the user to enter the index of an element
    5·1 answer
  • Question 1 of 10 Chase lives in Oregon but works for a company that is located in Florida. What business trend is this an exampl
    11·2 answers
  • Please
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!