Rolling a Six-Sided Die 60,000,000 Times
To show that the numbers produced by nextInt
occur with approximately equal likelihood, let’s simulate 60,000,000 rolls of a die with the application in Fig. 6.7. Each integer from 1 to 6 should appear approximately 10,000,000 times. Note in line 18 that we used the _
digit separator to make the int
value 60_000_000
more readable. Recall that you cannot separate digits with commas. For example, if you replace the int
value 60_000_000
with 60,000,000
, the JDK 8 compiler generates several compilation errors throughout the for
Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.