Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class DiceRolls {
- public static int howBig = 6;
- public static int[] rolls;
- public static int noRolls =5;
- public static int[] fillRolls(int size, int howMany) {
- int[] destArray = new int[howMany];
- for (int i=0; i<howMany; i++) {
- Random dice = new Random();
- destArray[i] = dice.nextInt(size)+1;
- }
- return destArray;
- }
- public static boolean isYhatzee(int[] testArray) {
- int thenumber = testArray[0];
- int count = 0;
- for (int i=0; i<testArray.length; i++) {
- if (testArray[i] == thenumber) {
- count++;
- }
- }
- if (count == 5) {
- return true;
- } else return false;
- }
- public static void main(String[] Args) {
- for (;;) {
- rolls = fillRolls(howBig, noRolls);
- if (isYhatzee(rolls)) {
- System.out.println("Yhatzee Found.");
- System.out.println("The number was: " + rolls[0]);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement