title: How do you do re-rolls in a yahtzee program in java?
body: <p>I've been working at an assignment for my intro to Java class, and I can't figure out how to accomplish the two things I need to do.</p>
  
  <p>What I have now: I have created an array that rolls five dice, and displays the results. The code I have is as follows...</p>
  
  <pre><code>package operation.pkg7;
  
  import java.util.Random;
  import java.util.Scanner;
  public class Operation7 {
   public static void main(String[] args) 
  {    
  
  
      int[] dice = new int[5];
   Random r = new Random();
  
   //This makes the dice 
   for (int i = 0; i &lt; 5; i++) {
   dice[i] = r.nextInt(6) + 1;
   }
   //This displays the dice rolls
   for (int i = 0; i &lt; 5; i++) {
   System.out.print("Roll " + (i+1) + ":" );
   System.out.print(" " + dice[i] + " ");
   }
   System.out.println();
   //..........................................
   int[] counts = new int[6];
   for (int i = 0; i &lt; 6; i++){
   counts[i] = 0;
   }
  
   //count up the values
   for (int i = 0; i &lt; 5; i++) {
   int diceIndex = dice[i] - 1;
   counts[diceIndex]++;
   }
  System.out.println();
   for (int i = 0; i &lt; 6; i++){
   System.out.println("The number of " + (i+1) + "s is : " +
  counts[i]);
  }
  }
  }
  </code></pre>
  
  <p>Now, I successfully gives me the results of the die rolls, but I'm having problems figuring out how to do re-rolls. This is an example of what I'm wanting the program to ask for after displaying the initial die roll...</p>
  
  <pre><code>Roll 1: 2 Roll 2: 6 Roll 3: 1 Roll 4: 4 Roll 5: 2
  
  Would you like to re-roll any dice? y/n
  y
  
  Which dice would you like to re-roll? 1-5
  2, 3, 4
  
  Roll 1: 2 Roll 2: 3 Roll 3: 2 Roll 4: 3 Roll 5: 2
  
  Would you like to re-roll any dice? y/n
  n
  
  Roll 1: 2 Roll 2: 3 Roll 3: 2 Roll 4: 3 Roll 5: 2
  </code></pre>
  
  <p>That's the goal. Once I do that, I need to make the program display the best possible score... For example, if there are two threes and three twos, it needs to say it's a full house, or display yahtzee if there are five of the same number etc.</p>
  
  <p>Anyone have any advice? </p>