I'm trying to get a calculation done in a loop but don't want it to print until after all loop are done. It will print but the calculation isn't done. Please help.
import java.util.*;
public class FlipCoin
{
public static void main(String[] args)
{
String choiceString;
final String HEADS = "Heads";
final String TAILS = "Tails";
int coinToss = 1;
double result;
int heads = 1;
int number = heads + 1;
int percentage1 = number * 10;
int percentage2 = 100 - percentage1;
while(coinToss <= 10)
{
result = (Math.random());
if(result <= .5)
{
choiceString = HEADS;
heads = 1;
}
else
choiceString = TAILS;
System.out.println("Cointoss " + coinToss + " came up " + choiceString);
coinToss++;
number = heads + 1;
}
System.out.println("The percentage of tosses that were heads is " + percentage1 + "%" +
"\n& the percentage of tosses that were tails is " + percentage2 + "%");
}
}