Advertisement
Shavit

P. 49 Ex. 10.39

Jan 7th, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Random;
  5.  
  6. public class CubeBooleanScouts {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         final int CUBE_SIZE = 6;
  12.        
  13.         Random r = new Random();
  14.        
  15.         int current = 0;
  16.         boolean[] cube = new boolean[CUBE_SIZE];
  17.         boolean found = false;
  18.        
  19.         for(int i = 0; i < CUBE_SIZE; i++)
  20.             cube[i] = false;
  21.        
  22.         while(!found)
  23.         {
  24.             current = 1 + (r.nextInt(6));
  25.             if(cube[current - 1])
  26.                 found = true;
  27.             else
  28.                 cube[current - 1] = true;
  29.         }
  30.        
  31.         System.out.printf("The winning number is %d.", current);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement