Final 1
Code
///Matthew Hughs
///Period 5
///Final
///Final.java
///1/20/2016
import java.util.Random;
import java.util.Scanner;
public class Final
{
public static void main( String[] args )
{
Scanner kb = new Scanner(System.in);
Random r = new Random();
int tale = 0;
int head = 0;
System.out.println("How many flips would you like ");
int flip = kb.nextInt();
if (flip > 0 && flip < 2100000000)
{
for (int x = 0; x <= flip; x++)
{
int y = 1 + r.nextInt(2);
if(y == 1)
{
head++;
}
else if (y == 2)
{
tale++;
}
}
System.out.println("You flipped " + head + " heads and " + tale + " tales");
double probH = (double)head / flip;
double probT = (double)tale / flip;
System.out.println("The Prob of heads is " + probH + " and tales is " + probT);
}
else
{
System.out.println("Ici Pci");
}
}
}
Picture of the output