Final #1

Code

/// Name: Connor Siri
/// Period: 7
/// Program Name: Final
/// File Name: Final.java
/// Date Finished: 1/21/2015
import java.util.Scanner;
import java.util.Random;

public class Final
{
	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);
    } //The if statements work well for specific variables and for determining guidlines when do and while loops work well with large numbers and keeping track of them as they change
    //the larger the number the closser to .50 you get because it evens out. so 2100000000 is the best number to use to get close to .50 tails and .50 heads
}

            
        
    

Picture of the output

Assignment1.html