Skip to main content

help for little problem

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
marck_kh
Offline
Joined: 2012-02-26

hi every boddy.can any one help me for a program that simulates coin-flipping ?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sunil.chahar1
Offline
Joined: 2012-03-02

****program that simulates coin-flipping****

class Toss {
public final int HEADS = 0;
static int countH = 0;
static int countT = 0;

private static int face;

public static void flip() {
face
= (int) (Math.random() * 2);
}

public String toString() {
String faceName;
if (face == HEADS) {
faceName
= "Heads";
countH
++;
} else {
faceName
= "Tails";
countT
++;
}
return faceName;
}

public static void main(String[] args) {
System.out.println("Outcomes:");
do {
flip
();
System.out.println(new Toss().toString());
} while (countH != 10);
System.out.println("Number of Tails: " + countT);
}
}