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]
4 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]4 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]4 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
Define and discuss the difference between micronutrients and macronutrients. Also, discuss their importance in the body at rest
almond37 [142]

Answer:

Macronutrients are simply nutrients the body needs in a very high amount e.g Carbohydrate.

MicroNutrients are simply nutrients the body needs but in little amount e.g  Minerals.

Explanation:

So for further breakdown:

What are nutrients? Nutrients are essential elements that nourish the body in different capacities. We as humans get most of out nutrients from the food and water we ingest.

Now about Macro Nutrients: From the prefix "Macro" which means large, we can infer that macro nutrients are elements need by the body for the fundamental processes of the body, deficiency in this nutrients are very easy to spot. Examples are: Carbohydrates, Protein, Fats amd Water.

Micro Nutrients: In relation to macro nutrients this are elements that the body needs but are not needed in Large quantities. They mostly work like supporting nutrients. Most chemical activities like reaction that occur in the body are a function of micro nutrients. Defiencies in micrp nutrients may take some time to spot e.g Minerals and Vitamins

In regards to exercise: Macro nutrients are the essential ones here since they are the ones that generate energy. PS: micro nutrients dont generate energy.

In regards to rest: Both the Macro and Micro Nutrients are essentail for the overall well being of the body.

5 0
3 years ago
Car insurance incentives and discounts are available depending on _____. A. school attendance and driver skill B. vehicle type a
WARRIOR [948]

Answer:D. Location, vehicle type, and driving habits

5 0
3 years ago
Read 2 more answers
What is the effect of connecting
IrinaVladis [17]

Answer: A capacitor connected across the output allows the AC signal to pass through it and blocks the DC signal, thus acting as a high pass filter. The output across the capacitor is thus an unregulated filtered DC signal. This output can be used to drive electrical components like relays, motors, etc.

Explanation:

4 0
3 years ago
Compute L, T, M, LC, and R and stations of the BC and EC for the circular curve with the given data of: I (delta) = 22°15′00" an
Mars2501 [29]

Answer:

L = 475.718

T = 240.89 ft

M = 23.0195

LC = 472.728

R = 1225 ft

Explanation:

See the attached file for the calculation.

8 0
3 years ago
Hi I don't know of yall remeber me, but I'm Jadin aka J. I am looking for my friend group, that I have missed but can't find cau
kirill [66]

Answer:

The young lady was his daughter.The shoemaker was frightened when he saw that she wants to sit near him and took his knife to frighten her and leave him alone to do his work

Explanation:

could uh name them since if i know any i would surely tryin help

7 0
2 years ago
Other questions:
  • Define various optical properties of engineering materials
    11·1 answer
  • A heat engine that receives heat from a furnace at 1200°C and rejects waste heat to a river at 20°C has a thermal efficiency of
    14·1 answer
  • An operating gear box (transmission) has 350 hp at its input shaft while 250. hp are delivered to the output shaft. The gear box
    10·1 answer
  • How does refrigeration preserve food and dead bodies​
    12·2 answers
  • The pressure intensity at a point in a fluid is equal in all directions a.true b.false​
    12·1 answer
  • Wave flow of an incompressible fluid into a solid surface follows a sinusoidal pattern. Flow is two-dimensional with the x-axis
    13·1 answer
  • Select the correct answer.
    6·1 answer
  • ) If the blood viscosity is 2.7x10-3 Pa.s, length of the blood vessel is 1 m, radius of the blood vessel is 1 mm, calculate the
    13·1 answer
  • Explain the S.A. co-ordinate system used in surveying
    9·1 answer
  • Why not just put all the set up steps within each step? it is because we want to keep our code __ ? (3 letters)
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!