lundi 8 janvier 2018

How to generate a random character out of a choice of two in Java?

I want to create a code that has a 50% chance of returning the string, "h", and the other 50% would return "t". I understand there is a way of generating random strings in Java, but how would I restrict it to the point where you could only get 'h', and 't' from it? EDIT:

It's a simple game of heads and tails. User inputs either h (heads) or t (tails) and the code generates the random answer.




Aucun commentaire:

Enregistrer un commentaire