aspose file tools*
The moose likes Beginning Java and the fly likes flipping coin program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "flipping coin program" Watch "flipping coin program" New topic
Author

flipping coin program

nathan gibson
Ranch Hand

Joined: Sep 16, 2009
Posts: 120


i have been working on this code that tells that gives a random number and interprets it as a heads or tail on a coin and therefore predicts the probability of a 50/50 chance. the only problem is that i need to add something to the code to where it will automatically tell me how many heads and how many tells it returns. thank you in advance for any help.
Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
Hi Nathan,

You can use a variable for example headCount and increment it every time a head is flipped. With this and the flip count you know the number of heads and tails.
nathan gibson
Ranch Hand

Joined: Sep 16, 2009
Posts: 120
i think i get what you are saying, but my problem is that i really dont know how to translate that into code that will work with my program. im a beginner, sorry.
Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
No problem, we are here to help beginners.

You can do this like this:

nathan gibson
Ranch Hand

Joined: Sep 16, 2009
Posts: 120


it still isnt quite working correctly. im sure it is my own fault for making this more difficult than it is, but the program is supposed to ask me for the number of flips, it is supposed to output something like this,
Program Output
Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
Just think about what you want. You wolud like to write out whether a tail or a head is flipped and you wolud like to write out the random number for every flip. But what about the number of tails and number of heads? Do you really want to print them out after every flip? I don't think so. So the only thing to do is to put the code which prints the number of heads and tails to the end of the program.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: flipping coin program
 
Similar Threads
cant get counters to work correctly
simple simple jave game
Wanting to ask user to keep "inputting" at the command prompt until a condition is reached
program to calculate male to female ratio of a given number
coin flip trouble!!