Advertisement
Shavit

P. 182 Ex. 7.32

Nov 5th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5. import java.util.Random;
  6.  
  7. public class Backgammon {
  8.  
  9.     public static void main(String[] args)
  10.    
  11.     {
  12.         Scanner in = new Scanner(System.in);
  13.         Random r = new Random();
  14.        
  15.         int x, y;
  16.        
  17.         for(int i = 0;;i++)
  18.         {
  19.             x = 1 + r.nextInt(6);
  20.             y = 1 + r.nextInt(6);
  21.            
  22.             if(((x == 5) && (y == 6)) || ((x == 6) && (y == 5)))
  23.             {
  24.                 System.out.printf("Backgammon! It took %d tries to reach this result", i);
  25.                 break;
  26.             }
  27.         }
  28.        
  29.         in.close();
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement