public class Test2 {
static final String[] NUMBERS = { "First", "Second", "Third", "Fourth",
"Fifth", "Sixth", "Seventh", "Eighth" };
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out
.println("For each coin toss entereither 'h' for heads ot 't' for tails. ");
int heads = 0, tails = 0;
for (int i = 0; i < NUMBERS.length; ++i) {
System.out.print(NUMBERS[i] + " toss: ");
System.out.flush();
String c = in.readLine();
try {
switch (c.charAt(0)) {
case 'h':
++heads;
break;
case 't':
++tails;
break;
public class Hoge {
static final double TRY_COUNT = 8;
static final String[] NUMBERS = new String[]{
"First",
"Second",
"Third",
"Fourth",
"Fifth",
"Sixth",
"Seventh",
"Eight"
};
static final String[] RESULT = new String[]{"h", "t"};
public static void main(String[] args) {
System.out.println("For each coin toss entereither 'h' for heads ot 't' for tails.");
int[] sum = new int[2];
for (int i = 0; i < 8; i++){
int result = toss();
System.out.println(NUMBERS[i]+":"+RESULT[result]);
sum[result]++;
}
System.out.println("count:"+TRY_COUNT);
System.out.println("Number of heads: "+sum[0]);
System.out.println("Number of tails:"+sum[1]);
System.out.println("Percent heads:"+sum[0]/TRY_COUNT);
System.out.println("Percent tails:"+sum[1]/TRY_COUNT);
}
public static int toss(){
return (int)(Math.random() * 2);
}
}
static final String[] NUMBERS = new String[] { "First", "Second", "Third",
"Fourth", "Fifth", "Sixth", "Seventh", "Eight" };
static final double TRY_COUNT = NUMBERS.length;
public static void main(String[] args) {
int result[] = new int[2];
for (int i = 0; i < TRY_COUNT; i++) {
String str = JOptionPane.showInputDialog(null, NUMBERS[i]
+ " coin toss enter "
+ "either 'h' for heads ot 't' for tails. ");