Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3.  
  4. public class DiceRolls {
  5.     public static int howBig = 6;
  6.     public static int[] rolls;
  7.     public static int noRolls =5;
  8.    
  9.     public static int[] fillRolls(int size, int howMany) {
  10.         int[] destArray = new int[howMany];
  11.         for (int i=0; i<howMany; i++) {
  12.             Random dice = new Random();
  13.             destArray[i] = dice.nextInt(size)+1;
  14.         }
  15.  
  16.         return destArray;
  17.     }
  18.    
  19.     public static boolean isYhatzee(int[] testArray) {
  20.         int thenumber = testArray[0];
  21.         int count = 0;
  22.         for (int i=0; i<testArray.length; i++) {
  23.             if (testArray[i] == thenumber) {
  24.                 count++;
  25.             }
  26.         }
  27.         if (count == 5) {
  28.             return true;           
  29.         } else return false;
  30.     }
  31.    
  32.  
  33.     public static void main(String[] Args) {
  34.  
  35.         for (;;) {
  36.             rolls = fillRolls(howBig, noRolls);
  37.             if (isYhatzee(rolls)) {
  38.                 System.out.println("Yhatzee Found.");
  39.                 System.out.println("The number was: " + rolls[0]);
  40.                 break;
  41.                 }
  42.             }
  43.         }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement