title: About requesting users to enter arbitrary times of input and switching values in the array
body: <p>I am trying to code a method <code>throwAgain(int[] dice)</code>. I was told to switch the values in the dice[] (the dice has only 5 indexes) and the values in the specified index (it means which die) the user asked to changed needed to swap with random number ranged from 1 to 6.</p>
  
  <p><code>rollDie()</code> is the function that generates the six numbers. Note: anything else other than integer 1 to 6  and two same integers are invalid inputs.</p>
  
  <p>I could not figure how to code the part that the users can enter up to 4 inputs. I do not know how to terminate the Scanner say after one or two or three or four inputs are entered. In addition, I do not think the way I code the program to determine what input it is could help me to swap the numbers in the array. </p>
  
  <p>Reference Sample: </p>
  
  <pre><code>Original array dice[]= 6 3 2 5 5
  ("List which die to throw again: 3 6") 
  invalid input!
  ("List which die to throw again: 3 3")
  invalid input!
  ("List which die to throw again: 3 4") 
  output: 6 3 5 3 5
  </code></pre>
  
  <hr>
  
  <pre><code>public static void throwAgain(int[] dice){
       Scanner input= new Scanner(System.in);
       System.out.print("List which die to throw again: ");
       String a= new String("");String b= new String("");
       String c= new String("");String d= new String("");
       a= input.next();b= input.next();c= input.next();
       d= input.next();
  
       if (a.equals("1")||b.equals("1")||c.equals("1")||d.equals("1")){
           dice[0]=rollDie();
       }else if (a.equals("2")||b.equals("2")||c.equals("2")||d.equals("2")){
           dice[1]=rollDie();
       }else if (a.equals("3")||b.equals("3")||c.equals("3")||d.equals("3")){
           dice[2]=rollDie();
       }else if (a.equals("4")||b.equals("4")||c.equals("4")||d.equals("4")){
           dice[3]=rollDie();
       }else if (a.equals("5")||b.equals("5")||c.equals("5")||d.equals("5")){
           dice[4]=rollDie();
       }
  }
  </code></pre>
  
  <p>This is my edited methods: 
           Scanner input= new Scanner(System.in);
           System.out.print("List which die to throw again: ");</p>
  
  <pre><code>      while (input.hasNextLine()) {
              String theLine = input.nextLine();
              String[] split = theLine.split(" ");
              /*for (int i = 0; i &lt; split.length; i++) {
                  System.out.println(split[i]);
                  // Do something with each entry
              }*/
            for(int i=0; i&lt;=split.length-1;i++){
              System.out.print(split[i]);
              if (split[i].equals("1")){
                   dice[0]=rollDie();
               }else if (split[i].equals("2")){
                   dice[1]=rollDie();
               }else if (split[i].equals("3")){
                   dice[2]=rollDie();
               }else if (split[i].equals("4")){
                   dice[3]=rollDie();
               }else if (split[i].equals("5")){
                   dice[4]=rollDie();
               }
            }
          }
          System.out.println(dice);
  }
  </code></pre>
  
  <p>The result is the same as the input. I just could not figure out what errors it has. And also I wanted to use a for loop to limit up to four times of input. I do not if it is a good idea. I tried to do it that way, but it always executed four times. I wanted it to stop whenever the user hit the enter key whether he only enters one input or two input or more but less than four. </p>