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
A viscometer may be created by using a pair of closely fitting concentric cylinders and filling the gap between the cylinder wit
kari74 [83]

Answer:

The viscosity of the fluid is 6.05 Pa-s

Explanation:

The viscosity obtained from a rotating type viscometer is given by the equation

\mu =\frac{3Tt}{2\pi \omega R_o(R_o^3-R_i^3)}

where

T is the torque applied in the viscometer

't' is the thickness of gap

\omega is the angular speed of rotation

R_o,R_i are the outer and the inner raddi respectively

Since it is given that

\omega =100rpm=\frac{100\times 2\pi }{60}=10.47rad/sec

Applying the values in the above relation we get

\mu =\frac{3\times 0.021\times 0.02\times 10^{-3}}{2\pi \times 10.47\times 37.5\times 10^{-3}(37.52^3-37.5^3)\times 10^{-9}}=6.04Pa-s

5 0
3 years ago
A nuclear power plant based on the Rankine cycle operates with a boiling-water reactor to develop net cycle power of 3 MW. Steam
rewona [7]

Answer:

xD

Explanation:

Nope

6 0
3 years ago
6.
Licemer1 [7]

Answer:

d

none of the above

hope this is helpful

7 0
3 years ago
A. Briefly define identity theft.
stira [4]

Answer:

Pharming

Phishing

Explanation:

Pharming is used equal like Phishing, because using fake websites, but in this case, is not necessary spam in your email.

Phishing is used like spam, and they pretend to be real companies by email, if you click in the email you will go a supposedly a real website, you put your information like passwords in these websites

You can prevent these techniques using antivirus and you can verify the websites because fake websites don't have the https:// protocol.

A business can prevent this issue using corporatize email and configuring the company network with security protocols and encrypt the information.

3 0
3 years ago
Design complementary static CMOS circuits with minimized number of transistors to realize the following Boolean functions (hint:
Pie

Answer:

as pull up network. the metteing point of pull down and pull up is the point where we take the output

note 1: if two n-mos are connected in series it gives logical AND and p-mos paralle gives logical-AND

note 2: if two n-mos are connected in parallel it gives logical OR and p-mos series gives logical-OR

note 3: output is always complement of what we implement

example Y= (AB)'

image attached

A) F = (ABC + D(A+B) )'

pulldown:

this can be realize by takeing three n-mos in series which gives ABC ,two n-mos are parallel which in series with another n-mos whic gives D(A+B), now connect ABC and D(A+B) in parallel

pull up

this can be realize by takeing three p-mos in parallel which gives ABC ,two p-mos are series which is in serires with

another p-mos whic gives D(A+B), now connect ABC and D(A+B) in series

the out put will be (ABC + D(A+B) )'

so we require total 6-mos and 6-pmos total 12mos transistors

B) F = AC + BD

pull down

this can be realize by takeing two n-mos in series which gives AB ,two n-mos are in series

which whic gives BD, now connect AC and BD in parallel

pull up

this can be realize by takeing two p-mos in parallel which gives Ac ,two p-mos are in parallel

which whic gives BD, now connect AC and BD in series

the output is (AC+BD)'

to avoid the complement we have to connect the output to c-mos inverter then we get AC+BD

so we require 5-nmos, 5-pmos total 10 mos transistors

8 0
3 years ago
Other questions:
  • A battery is an electromechanical device. a)- True b)- False
    6·1 answer
  • What is poop made out of
    13·2 answers
  • A gas within a piston–cylinder assembly undergoes an isother- mal process at 400 K during which the change in entropy is −0.3 kJ
    10·1 answer
  • NEED HELP PLEASE
    15·1 answer
  • 1. Two aluminium strips and a steel strip are to be bonded together to form a composite bar. The modulus of elasticity of steel
    11·1 answer
  • A six-lane freeway (three lanes in each direction) in rolling terrain has 10-ft lanes and obstructions 5 ft from the right edge.
    9·1 answer
  • When an object is plumb, it is _____.
    11·2 answers
  • DUS 14. Next → Post Test: Engineering Systems and Te 14 Select the correct answer.. Which of these is a unit of heat? O A. joule
    6·1 answer
  • What type of control would describe training, inspection, and housekeeping?
    7·1 answer
  • Flip-flops are normally used for all of the following applications, except ________. logic gates data storage frequency division
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!