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
Hi all, could you solve this please?<br> What is the value of the resistance R
Kazeer [188]

Answer:

try to 36v power and take 1a and intersect to 3

5 0
3 years ago
A 0.4-W cylindrical electronic component with diameter 0.3 cm and length 1.8 cm and mounted on a circuit board is cooled by air
Katyanochek1 [597]

Answer:

The surface temperature of the component 54.6 degrees celsius.

Explanation:

Please see attachment.

7 0
3 years ago
Gshyevdnmdcicm gngjc
Len [333]

This is not a valid question. Please try again.

4 0
3 years ago
The goal of a command enconomy is to
Svetllana [295]

Answer:

manage country economies in which is help responsible by a government in place.

Explanation:

5 0
4 years ago
Tubing cutters for copper tube are only available in one stlye true or false
Ratling [72]

Answer:

please how are you death for me account

3 0
4 years ago
Other questions:
  • A welding rod with κ = 30 (Btu/hr)/(ft ⋅ °F) is 20 cm long and has a diameter of 4 mm. The two ends of the rod are held at 500 °
    5·1 answer
  • The head difference between the inlet and outlet of a 1km long pipe discharging 0.1 m^3/s of water is 0.53 m. If the diameter is
    11·1 answer
  • A clay sample has a wet mass of 417 g, a volume of 276 cm3, and a specific gravity of 2.70. When oven dried, the mass becomes 22
    10·1 answer
  • The Energy Losses Associated with Valves and Fittings: a)- are generally associated with a K factor b)- are generally associated
    10·1 answer
  • There are three MUXes in the EX stage. Among them, the 2 MUXes located at the top is meant to provide correct ALU source data 1
    13·1 answer
  • _______________ is an effective way to manage waste in a shop.
    13·1 answer
  • Which of these credit building options do you personally think is the easiest method that you can see yourself doing? Explain yo
    8·1 answer
  • Which of the following elements found in fertilizer helps plants produce fruit?
    15·2 answers
  • What is the total resistance of three resistors in parallel with values of 2 ohms, 4 ohms, and 4 ohms?
    12·1 answer
  • What are the reasons why fine grained of alkali igneous rocks can not be used in cement
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!