The problem goes like this: Make the program throw the coin 100 times. Then sum the 1s and 2s. I succesfully made the throwing part with Math.random and for, but how can I sum the output 1s and 2s?
To make your posts better (and therefore easier to get answers) be sure to create a meaningful subject line. "Java problem" tells us nothing about what the problem is. I've changed it for you this time.
All things are lawful, but not all things are profitable.
I don't like to see arithmetic with Math#random() to get an int. See this discussion. If you have a binary choice, either one thing or a second, consider Random#nextBoolean() instead. Somebody hasalready suggested a method with a boolean return type.
posted 2 months ago
Junilu Lacar wrote:The idiom for iterating 100 times in Java is . . .
There is another reason for that idiom: it always works on arrays, etc., without throwing an out of bounds Exception.