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
typedef struct bitNode { int data; struct bitNode *left; struct bstNode *right; } bstNode; int solve(bstNode* root) { if (root =
Sergio039 [100]

Answer:

The ten numbers to be filled in the blanks are: 18, 7, 7, 11, 18, 36, 3, 8, 13, 50.

Explanation:

keeps on going to the left node until node->left == NULL;

now at Node 18;

left = right = 0; hence condition is not satisfied

18 is printed first.

the value 18 is returned .

Then we reach at 4;

from there we move to 7;

just like 18, similar things happen with 7 and 7 is printed, the value 7 is returned.

Now coming to Node 4,

left = 0, right = 7 ; hence the condition is satisfied & res = 7; 7 is printed.

For Node 16, left = 7 ; right = 11(but for this we visit 11 first and 11 is printed)

for 16; condition is satisfied; res = 7 + 11 = 18 ; 18 is printed

Now for 5; left = right = 18; the condition is satisfied; so res = 18 + 18 = 36; 36 is printed

Next we visit Node 3; 3 is printed & 3 is returned

Then Node 8 ; 8 is printed & 8 is returned

for Node 13; left = 3, right = 8 ; condition is not satisfied, 13 is printed.

For Node 50; left = 36 right = 13 ; condition is not satisfied hence 50 is printed.

So the order of printing is  18 7 7 11 18 36 3 8 13 50.

4 0
3 years ago
3. If nothing can ever be at absolute zero, why does the concept exist?
Tanzania [10]

The absolute zero in temperature refers to the minimal possible temperature. It is the temperature at which the molecules of a system stop moving, so it is a really useful reference point.

<h3>Why absolute zero can't be reached?</h3>

It would mean that we need to remove all the energy from a system, but to do this we need to interact with the system in some way, and by interacting with it we give it "some" energy.

Actually, from a quantum mechanical point of view, the absolute zero has a residual energy (so it is not actually zero) and it is called the "zero point". This happens because it must meet <u>Heisenberg's uncertainty principle</u>.

So yes, the absolute zero can't be reached, but there are really good approximations (At the moment there is a difference of about 150 nanokelvins between the absolute zero and the smallest temperature reached). Also, there are a lot of investigations near the absolute zero, like people that try to reach it or people that just need to work with really low temperatures, like in type I superconductors.

So, concluding, why does the concept exist?

  • Because it is a reference point.
  • It is the theoretical temperature at which the molecules stop moving, defining this as the <u>minimum possible temperature.</u>

If you want to learn more about the absolute zero, you can read:

brainly.com/question/3795971

3 0
2 years ago
What is the angular velocity (in rad/s) of a body rotating at N r.p.m.?
Darina [25.2K]

Answer:

0.1047N

Explanation:

To solve this problem we must remember the conversion factors, remembering that 1 revolution equals 2π radians and 1min equals 60s

N\frac{rev}{min} \frac{2\pi }{1rev} \frac{1min}{60} =N\frac{2\pi }{60} =0.1047N

in conclusion, to know how many rad / s an element rotates which is expressed in Rev / min we must only multiply by 0.1047

3 0
3 years ago
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Vlad [161]

Answer:

Explanation:

you need more information x

7 0
3 years ago
Two particles have a mass of 7.8 kg and 11.4 kg , respectively. A. If they are 800 mm apart, determine the force of gravity acti
aleksley [76]

Answer:

A) About 9.273 \times 10^{-9} newtons

B) 76.518 newtons

C) 111.834 newtons

Explanation:

A) F_g=\dfrac{GM_1M_2}{r^2} , where G is the universal gravitational constant, M 1 and 2 are the masses of both objects in kilograms, and r is the radius in meters. Plugging in the given numbers, you get:

F_g=\dfrac{(6.67408 \times 10^{-11})(7.8)(11.4)}{(0.8)^2}\approx 9.273 \times 10^{-9}

B) You can find the weight of each object on Earth because you know the approximate acceleration due to gravity is 9.81m/s^2. Multiplying this by the mass of each object, you get a weight for the first particle of 76.518 newtons.

C) You can do a similar thing to the previous particle and find that its weight is 11.4*9.81=111.834 newtons.

Hope this helps!

3 0
3 years ago
Other questions:
  • What Type of diploma do you need in order To the get into JMU
    12·1 answer
  • A compression ignition engine when tested gave an indicator card having area 3250mm^2 and length 73mm. The calibration factor wa
    10·1 answer
  • The news media often report an earthquake's magnitude on the Richter scale. Which of the following items are characteristics of
    14·1 answer
  • 1. What are the usual symptoms of brake issues?​
    15·1 answer
  • A Carnot heat engine absorbs 235 KW of heat from a heat source and rejects 164 KW to the atmosphere. Determine the thermal effic
    7·1 answer
  • Which happens when a wave passes through an opening
    12·2 answers
  • Complete the following sentence.
    10·1 answer
  • The annual average of solar photovoltaic energy in Phoenix is 6,720
    8·1 answer
  • Of the core elements of successful safety and health programs, Management Leadership, Worker Participation, and what else relate
    10·2 answers
  • The metric ruler is typically divided into
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!