I'm just starting Java and this is a coin flip program that I've written recently. So it's supposed to produce sequences of coin flips that meet the requirements that the user sets, however when it gets to the end it should ask if the user wants to go again. I'm having an issue where it will print the question twice when it gets down to end. I really need to figuer this out so any suggestions/clarifications for my code would be greatly appreciated.
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
outer: while (true) {
System.out.print("Ready to run a coin flip simulation. Enter the number of sequences: ");
int sequences = scan.nextInt();
System.out.print("How many heads should each sequence have? ");
int heads = scan.nextInt();
System.out.print("How many tails should each sequence have? ");
int tails = scan.nextInt();
System.out.println("Simulating Sequences");
int tFlips = 0;
int mFlips = 0;
for (int i = 1; i <= sequences; i++) {
int h = 0;
int t = 0;
String s = "";
while (t < tails || h < heads) {
if (Math.random() < 0.5) {
h++;
s += "H";
} else {
t++;
s += "T";
}
tFlips++;
}
if (t + h > mFlips) {
mFlips = t + h;
}
System.out.println(i + " - " + s);
h = 0;
t = 0;
s = "";
}
System.out.printf("The average number of flips was " + ((float) tFlips / sequences) + " and maximum was %d", mFlips);
System.out.println("\r\n");
boolean go = true;
while (go) {
System.out.print("Would you like to run another simulation? (y/n): ");
String c = scan.nextLine();
if (c.equalsIgnoreCase("y")) {
break;
} else if (c.equalsIgnoreCase("n")) {
break outer;
} else {
continue;
}
}
System.out.print("\r\n");
}
}