001package algs12; 002import stdlib.*; 003/* *********************************************************************** 004 * Compilation: javac Rolls.java 005 * Execution: java Rolls N 006 * Dependencies: Counter.java StdRandom.java StdOut.java 007 * 008 * % java Rolls 1000000 009 * 167308 1's 010 * 166540 2's 011 * 166087 3's 012 * 167051 4's 013 * 166422 5's 014 * 166592 6's 015 * 016 *************************************************************************/ 017 018public class XRolls { 019 public static void main(String[] args) { 020 args = new String[] { "1000000" }; 021 022 int T = Integer.parseInt(args[0]); 023 int SIDES = 6; 024 025 // initialize counters 026 Counter[] rolls = new Counter[SIDES+1]; 027 for (int i = 1; i <= SIDES; i++) { 028 rolls[i] = new Counter(i+1 + "'s"); 029 } 030 031 // flip dice 032 for (int t = 0; t < T; t++) { 033 int result = StdRandom.uniform(1, SIDES+1); 034 rolls[result].increment(); 035 } 036 037 // print results 038 for (int i = 1; i <= SIDES; i++) { 039 StdOut.println(rolls[i]); 040 } 041 } 042} 043