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
How can we calculate the speed of the output gear in a simple gear train? Explain with the help of an example.
Snowcat [4.5K]

Answer:

N_3=\dfrac{T_1}{T_3}N_1

Explanation:

In the diagram there three gears in which gear 1 is input gear ,gear 2 is idle gear and gear 3 is out put gear.

Lets take

Speed\ of\ gear 1=N_1

Number\ of\ teeth\ of\ gear 1=T_1

Speed\ of\ gear 3=N_3

Number\ of\ teeth\ of\ gear 3=T_3

All external matting gears will rotates in opposite direction with respect to each other.

So the speed of gear third can be given as follows

\dfrac{T_1}{T_3}=\dfrac{N_3}{N_1}

N_3=\dfrac{T_1}{T_3}N_1

3 0
3 years ago
- Viscoelastic stress relaxation
My name is Ann [436]

Explanation:

The correct answers to the fill in the blanks would be;

1. Viscoelastic stress relaxation refers to scenarios for which the stress applied to a polymer must decay over time in order to maintain a constant strain. Otherwise, over time, the polymer chains will slip and slide past one another in response to a constant applied load and the strain will increase (in magnitude).

2. Viscoelastic creep refers to scenarios for which a polymer will permanently flow over time in response a constant applied stress.

The polymer whose properties have been mentioned above is commonly known as Kevlar.

It is mostly used in high-strength fabrics and its properties are because of several hydrogen bonds between polymer molecules.

5 0
3 years ago
Why might construction crews want to install pipes before the foundation is poured
Crazy boy [7]

The answer is choice C

Explanation:

As during construction ,the site is cleared for all debris before laying out the foundation. Even the sewer lines are dug out .

So it will be useful for the construction crews to  connect the pipes to the sewer lines before the foundation is poured.

But usually the steps take in construction activity is:- first the site is cleared for the foundation to be poured  and once the foundation wall is set , then all utilities , including plumbing and electrical activities are done.,

After this process is over, the city inspector comes to check whether the foundation has been laid down as per the code of construction.

Only after that the rest of the construction activity follows through.

3 0
3 years ago
A motor car shaft consists of a steel tube 30 mm internal diameter and 4 mm thick. The engine develops 10 kW at 2000 r.p.m. Find
tresset_1 [31]

The maximum shear stress in the tube when the power is transmitted through a 4: 1 gearing is 28.98 MPa.

<h3>What is power?</h3>

Power is the energy transferred per unit time.

Torque is find out by

P = 2πNT/60

10000 = 2π x 2000 x T / 60

T =47.74 N.m

The gear ratio Ne / Ns =4/1

Ns =2000/4 = 500

Ts =Ps x 60/(2π x 500)

Ts =190.96 N.m

Maximum shear stress τ = 16/π x (T / (d₀⁴ - d₁⁴))

τ max =T/J x D/2
where d₁ = 30mm = 0.03 m

           d₀ = 30 +(2x 4) = 38mm =0.038 m

Substitute the values into the equation, we get

τ max = 16 x 190.96 x 0.038 /π x (0.038⁴ - 0.03⁴)

τ max = 28.98 MPa.

Thus, the maximum shear stress in the tube is 28.98 MPa.

Learn more about power.

brainly.com/question/13385520

#SPJ1

7 0
2 years ago
Metal and dirt are not considered contaminants to oll.<br> A) O True<br> B) O False
Likurg_2 [28]

Answer:

true

Explanation:

6 0
2 years ago
Read 2 more answers
Other questions:
  • Effect of feedback on the plant is to a) Control system transient response b) Reduce the sensitivity to plant parameter variatio
    15·1 answer
  • During the collision, is the magnitude of the force of asteroid A on asteroid B greater than, less than, or equal to the magnitu
    11·2 answers
  • Nitrate salts (NO3-), when heated, can produce nitrites (NO2-) plus oxygen (O2). A sample of potassium nitrate is heated, and th
    9·1 answer
  • Nitrogen can be liquefied using a Joule-Thomson expansioni process. This is done by rapidlyl and adiabatically expandign cold ni
    15·1 answer
  • WHAT IS A TOROID IN HYDRAULUCS?
    11·2 answers
  • Which of the following tells the computer wha to do
    12·1 answer
  • 8. What is the density of an object with a mass of 290.5 g and volume of 83 cm 3?​
    13·1 answer
  • The formation of faults in Earth's crust is an effect. What causes faults to form in the crust? Global Positioning System sensor
    9·1 answer
  • Which type of engineer is needed in the following scenario?
    8·2 answers
  • 3
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!