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
Luden [163]
3 years ago
10

java Write a program that simulates tossing a coin. Prompt the user for how many times to toss the coin. Code a method with no p

arameters that randomly returns either the String "heads"or the string "tails". Call this method in main as many times as requested and report the results.
Engineering
2 answers:
igomit [66]3 years ago
5 0

Answer:

The source code to this question has been attached to this response. Please download it and go through the code.

The source code contains comments explaining important segments of the code. Kindly read the comments carefully for better readability and understandability of the code.

Download java
max2010maxim [7]3 years ago
4 0

Answer:

The solution code is written in Java.

  1. public class Main {
  2.    public static void main(String[] args) {
  3.        Scanner inNum = new Scanner(System.in);
  4.        System.out.print("Enter number of toss: ");
  5.        int num = inNum.nextInt();
  6.        for(int i=0; i < num; i++){
  7.            System.out.println(toss());
  8.        }
  9.    }
  10.    public static String toss(){
  11.        String option[] = {"heads", "tails"};
  12.        Random rand = new Random();
  13.        return option[rand.nextInt(2)];
  14.    }
  15. }

Explanation:

Firstly, we create a function <em>toss()</em> with no parameter but will return a string (Line 14). Within the function body, create an option array with two elements, "heads" and "tails" (Line 15). Next create a Random object (Line 16) and use <em>nextInt()</em> method to get random value either 0 or 1. Please note we need to pass the value of 2 into <em>nextInx() </em>method to ensure the random value generated is either 0 or 1.  We use this generate random value as an index of <em>option </em>array and return either "heads" or "tails" as output (Line 17).

In the main program, we create Scanner object and use it to prompt user to input an number for how many times to toss the coin (Line 6 - 7). Next, we use the input num to control how many times a for loop should run (Line 9). In each round of the loop, call the function <em>toss() </em>and print the output to terminal (Line 10).  

You might be interested in
Consider a 6-bit cyclic redundancy check (CRC) generator, G = 100101, and suppose that D = 1000100100. 1. What is the value of R
dmitriy555 [2]

Answer:

The value of R is 10101

Explanation:

As per the given data

D = 1000100100

G = 100101

Redundant bit = 6-bits - 1-bit = 5-bits

No add fice zero to D

D = 100010010000000

Now calculate R as follow

R = D / G

R = 100010010000000 / 100101

R = 10101

Workings are attached with this question

3 0
3 years ago
Technician A says that diesel fuel system filters also include a water separator. Technician B says that water from the separato
Verizon [17]

Answer:

A is correct

Explanation:

water can cause several types of problems in a high pressure fuel injection system. Within reasonable and fairly broad limits, warmer fuel is better than cooler fuel. Some systems use a loop off the radiator system to help warm the fuel. No need to cool the fuel, especially with direct contact water.

6 0
3 years ago
Locução adjetiva e de portuges ou istoria
Alexxx [7]
No hablo espanol perdon amigo
3 0
2 years ago
A tank contains initially 2500 liters of 50% solution. Water enters the tank at the rate of 25 iters per minute and the solution
sergejj [24]

Answer:

Percentage of solution=32. 96%

Explanation:

Given that initially tank have 50% solution.It means that amount of solution=0.5 x 2500 =1250 lts

Lets take the amount of solution at time t = A

So

\dfrac{dA}{dt}=rate\ in\ solution -rate\ out\ solution

\dfrac{dA}{dt}=concentration\times rate\ in\ of\ water -concentration\times rate\ out\ of\ water

\dfrac{dA}{dt}=0\times 25-\dfrac{A}{2500}\times 50

\dfrac{dA}{dt}=-\dfrac{A}{50}

Now by integration

\ln A=-\dfrac{1}{50}t+C

Where C is the constant

Given that at t=0 ,A=1250

So C=\ln 1250

\ln A=-\dfrac{1}{50}t+\ln 1250

When t=20 min

\ln A=-\dfrac{1}{50}\times 20+\ln 1250

A=837.90

So percentage of solution after 20 min

=\dfrac{1250-837.9}{1250}\times 100

Percentage of solution=32. 96%

4 0
3 years ago
Jerry wants to manufacture flat metal sheets. Which process will he use?
Marina CMI [18]
Option choice d is the correct answer
5 0
3 years ago
Other questions:
  • Consider flow in between two parallel plates located a distance H from each other. Fluid flow is driven by the bottom plate movi
    15·1 answer
  • The wheel and the attached reel have a combined weight of 50lb and a radius of gyration about their center of 6 A k in = . If pu
    9·1 answer
  • Air enters the compressor of an air-standard Brayton cycle with a volumetric flow rate of 60 m3/s at 0.8 bar, 280 K. The compres
    10·1 answer
  • "Write a statement that outputs variable numItems. End with a newline. Program will be tested with different input values."
    15·1 answer
  • What are the desired characteristics or values for the following parameters of an ideal amplifier?o Phase change as a function o
    10·1 answer
  • Chandler is working on a school editing project. Because he copied 10 GB of raw footage to his computer, its memory is running l
    11·1 answer
  • Can you use isentropic efficiency for a non-adiabatic compressor?
    12·1 answer
  • Given frequency, what is the formula for the period of a wave?
    11·1 answer
  • Develop a simple Business plan as an entrepreneur​
    5·1 answer
  • What is the correct procedure for mounting the m240 on the m122a1 tripod after the pintle is attached to the receiver?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!