title: Master Mind Arrays
body: <p>I am currently working on a school project, where the assignment is to re-create the game "MasterMind" using Arrays and for loops, however, I am having difficulty correctly adding up the number of white pegs, and I get an output like this.</p>
  
  <pre><code>4
  7
  2
  1
  What is your guess? No spaces
  4444
  there are 1 reds, and 2 whites
  </code></pre>
  
  <p>As you can see, it incorrectly outputs the wrong amount of white pegs. Any advice and/or solutions to my issue would be much appreciated. </p>
  
  <pre><code>public static void MasterMind(){
          Scanner input = new Scanner(System.in);
          Random r = new Random();
          int red = 0, white = 0;
          int ball;
          int userInput;
          int[] ballNum;
          ballNum = new int[4];
          int[] Input;
          Input = new int[4];
          ball = r.nextInt(9999-1000)+1000;
          for (int i = 0; i &lt; 4; i++){
              ballNum[i] = ball%10;
              ball /= 10;
              System.out.println(ballNum[i]);
          }
          for (int d = 0; d &lt; 8; d++){
              System.out.println("What is your guess? No spaces");
              userInput = input.nextInt();
              for(int i = 0; i &lt; 4; i++){
                  Input[i] = userInput % 10;
                  userInput /= 10;
              }
              for (int i = 0; i &lt; 4; i++){
                  int m = 0;
                  int n = 0;
                  if(Input[i] == ballNum[i]){
                      red++;
                      Input[i] = 10000;
                  }
                  m++;
                  n++;
              }
              for(int i = 0; i &lt; 4; i++){
                  for(int j = 0; j &lt; 4; j++){
                      if(i != j &amp;&amp; Input[j] == ballNum[i]){
                          white++;
                          Input[j] = 1000000;
                      }
                  }
              }
              white -= red;
  
              if(white &lt; 0){
                  white = 0;
              }
              System.out.println("there are "+red+" reds, and "+white+" whites");
              white = 0;
              red = 0;
          }
      }
  </code></pre>