Spooky Code of the final
Code
//Darien Joslin
//period 6
//program FallFinal
// filename FallFinal.java
import java.util.Scanner;
import java.util.Random;
public class FallFinal
{
public static void main( String[] args ) {
Scanner input = new Scanner(System.in);
System.out.println("Bon jour! This program predicts the outcome of a coin toss, either heads or tails.");
System.out.println("Please select an amount of tosses in which you are interested in learning the outcome");
int flipNum = input.nextInt();
{
System.out.println(" Whoops! Your number was ");
if ( flipNum < 1 )
{
System.out.print("too small");
}
else
{
System.out.print("too large");
}
System.out.println("Please select a number between 1 and 2,100,000,000.");
}
Random r = new Random();
int flipsCompleted = 0;
int headTotal = 0;
int outcome = 0;
while ( flipsCompleted < flipNum );
{
outcome =r.nextInt(2);
headTotal= headTotal + outcome;
flipsCompleted++;
}
int tailTotal = flipsCompleted - headTotal;
System.out.println("In " + flipNum + " coin flips, " + headTotal + " heads were rolled and" + tailTotal + "tails were rolled.");
double headProbability = (double)headTotal / flipsCompleted;
double tailProbability = (double)tailTotal / flipsCompleted;
System.out.println("In this trial, the probability of rolling a head was " + headProbability +".");
System.out.println("The probability of rolling a tails was " + tailProbability + ".");
}
}
Picture of the output