Question
Asked Sep 30, 2019

Draw a flowchart for a program that shows the logic for a program that generates a random number.  The program will simulate tossing coin.  

check_circle

Expert Answer

Step 1

The following program will generate a random number 0 or 1. If the generated random number is 0, then it should display "heads". Else, if the generated random number is 1, then it should display "tails".

 

Source Code

//import the required package

import java.util.Scanner;

//definition of class

public class A {

 

            public static void main(String[] args) {

                        // declare the variables

                        int coin;

                        String s="";

                        coin=(int)(Math.random()*2);  //generation of a random number 0 or 1

                        System.out.println(coin);

                        if(coin==0)                  //check if coin is equal to 0 then assign "heads" to variable s

                        {

                            &nb...

0
heads
1
tails
help_outline

Image Transcriptionclose

0 heads 1 tails

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Which of the following is NOT logically equivalent to the rest: wx~y + w~z + wxyz + w~yz w(x + ~y +...

A: Using a Karnaugh Map to find the minimal sum-of-products for the expressions we get the following (c...

question_answer

Q: Write a statement that outputs variable numObjects. End with a newline. Program will be tested with ...

A: Note: The program code is written as per the user requirements.The code is commented well for better...

question_answer

Q: Using Java Eclipse IDE  (Average an array) Write two overloaded methods that return the average o...

A: Program Instructions:Take 10 double values using scanner class in an array.Call the method average w...

question_answer

Q: What can you tell me about Python computer language?

A: Python programming language:Python is a high level programming language.It is widely used in commerc...

question_answer

Q: Write a class named StockPrice. The class constructor should accept an array of stock prices as its ...

A: First of all ,you  need to create a class .The class name is StockPrice  in which you need to create...

question_answer

Q: //////////// //////////// //////////// how do i solve this problem in java?

A: Java is object- oriented programming language developed by James gosling in 1995. It is platform ind...

question_answer

Q: 1. /15 points] Consider the following function: Func1(A, n) * A is an array of integers 1 80; 2 for ...

A: a)Worst case running time of Func1:The random number between 1 to “n” is assigned to “k” in the give...

question_answer

Q: Consider the following grammar in BNF (start symbol is ) Which of the following sentences are in the...

A: Backus-Naur Form (BNF):BNF is a formal mathematical method to define the syntax of the programming l...

question_answer

Q: Part 1: Stack As mentioned in class, Python 3 provides the LifoQueue class as part of the Queue libr...

A: Import the given class in another file.Create the function postfix() which takes a string as its arg...