Ok, so, I'm bored like most people, and I decided to play and create different apps to build on my java programming skills.
I'm currently stumped on this flip a coin program. I am using a Random number class and asking it to add up the total heads/amount of flips.... but it's not working.
Any hints would be helpful. Currently taking my first Java Class and a University student, so don't judge too much :)
import java.util.*;
public class FlipaCoin
{
public static void main(String [] args)
{
Random rand= new Random();
boolean a;
while (a=true)
{
int flip=rand.nextInt(2);
int heads=0;
if (flip==1)
{
heads++;
}
double count=0;
double percentage=heads/count;
System.out.println(percentage);
count++;
if (percentage==50.0)
{
break;
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire