... // if counter is divisible by 5, start a new line of output
18            if (counter % 5 == 0)
19               System.out.println();
20            }
21         }
22      }
23   }

1  5  3  6  2
5  2  6  5  2
4  4  4  2  6
3  1  6  2  2

6  5  4  2  6
1  2  5  1  3
6  3  2  2  1
6  4  2  6  4

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.