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

Question

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

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...

### Want to see the full answer?

See Solution

#### 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

### Computer Science 