Final
Coin Flips
import java.util.Random;
import java.util.Scanner;
public class coin
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int n = 0, t, heads, tails;
heads = 0;
tails = 0;
System.out.println("Ok, how many times do you wanna flip the coin?");
t = keyboard.nextInt();
while ( n < t )
{
int flip;
flip = 1 + r.nextInt(2);
if ( flip == 1 )
{
heads++;
}
if ( flip == 2 )
{
tails++;
}
n++;
}
double pheads = heads * 100 / t;
double ptails = tails * 100 / t;
System.out.println("Ok, so you have " + heads + " heads and " + tails + " tails.");
System.out.println("");
System.out.println("That means you have "+pheads+" percent heads and "+ptails+" percent tails.");
//boom
}
}
Picture of the output