I'm writing a program where it tracks how many flips you want to perform and then it lists the results.
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
Random rand = new Random();
int flips;
int coin;
int i;
String result;
System.out.println("Welcome to the coin flip analyzer.");
System.out.print("How many flips? ");
flips = scnr.nextInt();
for (i = 0; i < flips; ++i) {
coin = rand.nextInt(2);
if (coin == 0) {
result = ("H");
System.out.print(result);
}
else {
result = ("T");
System.out.print(result);
}
}
}
For example, for a flips of 10:
Welcome to the coin flip analyzer.
How many flips? 10
HHTHTHHHTT
What I'm trying to change in my code is adding a space when a coin run ends. For example, the above result would look like:
HH T H T HHH TT