Here is the code I have so far. I'm not sure how to proceed from here. My goal is to make a program that outputs the probability of n amount of coin tosses, where n is the user input.
import java.util.Scanner;
public class toss{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of flips: ");
int n = scanner.nextInt();
double x = 0;
for(int i=1; i<n; i++)
{
if(Math.random() < 0.5)
{
x++;
}
System.out.println("P(H) = "+(double)x/n);
}
}
}
Again, I'm not looking for the code, just some advice on where to fix and what next. My knowledge is limited to for loops, ifs, whiles, and just the beginning of Strings.
Thanks in advance!