Assignemnt #Fall Final
Code
/// Name: Ryan Volko
/// Period: 7
/// Program Name: FallFinal
/// File Name: FallFinal.java
/// Date Finished: 1/21/2016
import java.util.Scanner;
import java.util.Random;
public class FallFinal
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int NF = 0;
int NH = 0;
int NT = 0;
int flip = 0;
System.out.println("How many flips do you want? ");
System.out.print("> ");
NF = keyboard.nextInt();
if ( NF <= 0 )
{
System.out.println("Sorry that number is too small");
System.out.println("How many flips do you want? ");
System.out.print("> ");
NF = keyboard.nextInt();
}
if (NF > 2100000000)
{
System.out.println("Sorry that number is too big");
System.out.println("How many flips do you want? ");
System.out.print("> ");
NF = keyboard.nextInt();
}
do
{
int x = 1 + r.nextInt(2);
if ( x == 1)
NH ++;
else
NT ++;
flip++;
}while ( flip != NF );
System.out.println("\n\n\n Heads = " + NH);
System.out.println("\n Tails = " + NT);
double PH = (double)NH/NT;
double PT = (double)NT/NH;
double PHH = PH/2;
double PTT = PT/2;
System.out.println("\n\n\nProbability of Head = " + PHH);
System.out.println("\nProbability of Tail = " + PTT);
} //do and while loops work well with keeping track of large numberds as they change while the if statements work well for determinign guidlines for specific varibles thats why I chose both
//the larger the number the closser to .50, as seen in my picture, you get so the best number to get to .50 heads and .50 tails is 2100000
}
Picture of the output