Semester 1 Exam and Display Probability
Code
/// Name: Marco Correa
/// Period: 5
/// Program Name: DisplayProbability
/// File Name: DisplayProbability.java
/// Date Finished: 1/20/2016
import java.util.Scanner;
public class DisplayProbability
{
public void flip(){
int tail = 0;
int head = 0;
int face;
System.out.println("Enter Number Of Rolls : ");
Scanner input = new Scanner ( System.in);
int rollTimes = input.nextInt();
for(int roll = 0 ; roll < rollTimes ; roll++){
face = (int)( Math.random() * 2 ) + 1;
if(face==1)
tail++;
else
head++;
}
System.out.printf("%d Times Tail, %d Times Head", tail, head);
}
}
Picture of the output