I am stuck in this code. I have to print results every 30 tosses for 500 total tosses.
I made the 30 but in the loops.
And also percentages are showing as 0
Help or hints would be much appreciated.
import java.util.Random;// program uses class Random
public class CoinTossing
{
public static void main (String [] args)
{
Random coinTosses = new Random();
System.out.println("START Coin Toss!");
int frequencyHeads=0;//maintains count of heads rolled
int frequencyTails=0;//maintains count of tails rolled
int percentageH;
int percentageT;
int totalTosses;
for (int toss = 1; toss <= 30; toss++)
{
int face = coinTosses.nextInt(2);
if (face == 0)
++frequencyHeads;
else
++frequencyTails;
}
totalTosses = frequencyHeads + frequencyTails;
percentageH = ((totalTosses - frequencyTails)/totalTosses);
percentageT = ((totalTosses - frequencyHeads)/totalTosses);
System.out.println("Number of tosses\t\tNumber of Heads\\ % \t\tNumber of Tails\\ %");
System.out.printf("\t%d\t\t\t\t%d %d\t\t\t\t%d %d", frequencyHeads + frequencyTails,frequencyHeads,percentageH, frequencyTails,percentageT);
}
}