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. 5.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, the compiler generates several compilation errors throughout the for
statement’s header (line 18) if ...
Get Java How To Program, Late 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.