import java.util.*;
public class Coin
{
private Random randomNumbers = new Random();
// flips a coin many times
public void flipCoins()
{
Scanner input = new Scanner( System.in );
int heads = 0;
int tails = 0;
int choice;
do
{
// display a menu
System.out.println( "1. Toss Coin" );
System.out.println( "2. Exit" );
System.out.print( "Choice: " );
choice = input.nextInt();
if ( choice == 1 )
{
if ( flip() )
heads++;
else
tails++;
System.out.printf( "Heads: %d, Tails: %d\n", heads, tails );
}
} while ( choice != 2 );
}
public boolean flip()
{
return randomNumbers.nextInt( 2 ) == 1;
}
}
This program flips a coin on user's prompts and results in true and false for Heads and Tails respectively,and gives the no. of heads and tails in the end.My question is where can I have the main method in this program ? Please help !