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
The uniform crate has a mass of 50 kg and rests on the cart having an inclined surface. Determine the smallest acceleration that
Lostsunrise [7]

Answer: smallest will be 000,.111 84.

Explanation:

5 0
3 years ago
Manufacturing employees who perform assembly line work are referred to as
mamaluj [8]

Answer:

C. assembly line workers.

Explanation:

8 0
3 years ago
Read 2 more answers
What does an engineer do? List as many types of engineers as you can.
BARSIC [14]

Answer:

Mechanical Engineering

Chemical Engineering

Civil Engineering

Explanation:

I got it from my old homework And I learn those at school ( Thank You For The Points)

7 0
3 years ago
List all the qualities of an engineer?
Dennis_Churaev [7]

Answer:

Math and Computer Skills. A qualified engineer should be good at math, at least through the level of calculus and trigonometry, and understand the importance of following the data when making design decisions.

Organization and Attention to Detail.  

Curiosity.  

Creativity.  

Critical Thinking.

Intuition.

Explanation:

6 0
2 years ago
Consider 2 hosts, Host A and Host B, transmitting a large file to a Server C over a bottleneck link with a rate of R kbps.
nevsk [136]

Answer:

i want coins sorry use a calculator or sum

Explanation:

kk

5 0
3 years ago
Other questions:
  • A soil had a liquid limit of 44, a plastic limit of 21, and a shrinkage limit of 14. In the summer, the in situ water content wa
    14·1 answer
  • For this question, you will be provided with data related to the count of website sessions by day for the past one hundred days.
    6·1 answer
  • A brittle intermetallics specimen is tested with a bending test. The specimen's width 0.45 in and thickness 0.20 in. The length
    5·1 answer
  • The position of a particle moving along a straight line is defined by the relation. s = t^3 – 6t^2 – 15t + 40, where s is expres
    13·1 answer
  • A soil has the following Green-Ampt parameters Effective porosity 0.400 Initial volumetric moisture content-15% Hydraulic Conduc
    6·1 answer
  • 1. What are the usual symptoms of brake issues?​
    15·1 answer
  • Airplanes typically have a Pitot-static probe located on the underside that measures relative wind speed as the airplane flies.
    6·1 answer
  • Which one is dependent variable?
    13·1 answer
  • Which type of Bridge is considered the strongest in both compression and tension?
    11·2 answers
  • Question Completion Status:
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!