Advertisement
Shavit

P. 49 Ex. 10.37

Jan 5th, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5. import java.util.Random;
  6.  
  7. public class RandomCube {
  8.  
  9.     public static void main(String[] args)
  10.    
  11.     {
  12.         final int CUBE_SIZE = 6;
  13.        
  14.         Scanner in = new Scanner(System.in);
  15.         Random r = new Random();
  16.        
  17.         int[] cube = new int[CUBE_SIZE];
  18.         int length;
  19.         int current;
  20.        
  21.         System.out.printf("Enter the nubmer of times you would like to throw the cube: ");
  22.         length = in.nextInt();
  23.        
  24.         for(int i = 0; i < length; i++)
  25.         {
  26.             current = 1 + (r.nextInt(6));
  27.             cube[current - 1]++;
  28.         }
  29.        
  30.         for(int i = 0; i < CUBE_SIZE; i++)
  31.             System.out.printf("The number of times ~%d~ was generated is %d.\n", i + 1, cube[i]);
  32.        
  33.         in.close();
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement