This program is supposed to simulate 200 coin flips and print out the length of the longest sequence of heads or tails.
Hey guys, I'm new at programming. I'm stuck in the middle of writing this. Can someone help me to understand the logic behind it? Any help would be appreciated.
public class CoinFlips{
public static void main(String[] args){
int headsCount=0;
int tailsCount=0;
int countTales=0;
int countHeads=0;
for (int i=0 ; i<=200; i++){
double x= Math.random();
if (x<0.5){
countTales++;
}
else {
countHeads++;
}
//I'm clueless!
}
}
}