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
Deffense [45]
3 years ago
9

In javaWrite a program that simulates flipping a coin to make decisions. The input is how many decisions are needed, and the out

put is either heads or tails. Assume the input is a value greater than 0.Ex: If the input is 3, the output is:tails heads headsFor reproducibility needed for auto-grading, seed the program with a value of 2. In a real program, you would seed with the current time. In that case, every program's output would be different, which is what is desired but can't be auto-graded.Note: A common student mistake is to create an instance of Random before each call to rand.nextInt(). But seeding should only be done once, at the start of the program, after which rand.nextInt() can be called any number of times.Your program must define and call the following method that returns "heads" or "tails".public static String HeadsOrTails(Random rand)
Engineering
1 answer:
Pavel [41]3 years ago
7 0

Answer:

// Program is written in Java Programming Language

// Comments are used for explanatory purpose

import java.util.*;

public class FlipCoin

{

public static void main(String[] args)

{

// Declare Scanner

Scanner input = new Scanner (System.in);

int flips;

// Prompt to enter number of toss or flips

System.out.print("Number of Flips: ");

flips = input.nextInt();

if (flips > 0)

{

HeadsOrTails();

}

}

}

public static String HeadsOrTails(Random rand)

{

// Simulate the coin tosses.

for (int count = 0; count < flips; count++)

{

rand = new Random();

if (rand.nextInt(2) == 0) {

System.out.println("Tails"); }

else {

System.out.println("Heads"); }

rand = 0;

}

}

You might be interested in
Pleaseeee help me with this!!
lilavasa [31]
Can you add a picture??
3 0
3 years ago
2. What is the main job of a cylinder head?
Anna11 [10]

Answer:

Explanation:

The cylinder head sits on the engine and closes off the combustion chamber. The gap that remains between the cylinder head and the engine is completed by the head gasket. Another task of the cylinder head is to ensure the constant lubrication of the cylinder        

3 0
3 years ago
This is just so I can flip the picture
Pepsi [2]

Answer:

ok

Explanation:

thx for points

7 0
4 years ago
A fair die is thrown, What is the probability gained if you are told that 4 will
Semmy [17]

Answer:

1/6

Explanation:

A dice has 6 sides, the probability of 4 appearing is 1/6.

7 0
3 years ago
A circuit contains four 100 ohm resistors connected in series. If you test the circuit with a DMM you should read a total resist
olga nikolaevna [1]
C is the correct answer
8 0
3 years ago
Other questions:
  • If the efficiency of the boiler is 91.2 % , the overall efficiency of the turbine, which includes the Carnot efficiency and its
    5·1 answer
  • . Steam is to be condensed from saturated vapor to saturated liquid in the condenser of a steam power plant at a temperature of
    5·1 answer
  • A ramp from an expressway with a design speed of 30 mi/h connects with a local road, forming a T intersection. An additional lan
    10·1 answer
  • A gas refrigeration system using air as the working fluid has a pressure ratio of 5. Air enters the compressor at 0°C. The high-
    8·1 answer
  • Assuming Stokes behavior, calculate the terminal settling velocity in standard air () for the following particles: (a) diameter
    5·1 answer
  • What overall material composition would be required to give a material made up of 50wt% mullite and 50wt% alumina at 1400°C?
    5·1 answer
  • What is the aim of reviewing a research paper?
    8·2 answers
  • 10. Which one of the following items would you expect to find on a floor framing plan?
    6·2 answers
  • Azimuth is another name for
    12·2 answers
  • If 9 + 10 = 21, then what is 10 + 10?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!