title: Calculating number of mines surrounding a cell in 2d array JAVA
body: <p>Hi so basically I'm trying to make a beginner version of minesweeper but i got a bit stuck.
  I'm able to get to the stage where i have a 2d array of chars while'*' means mine and ^ doesn't. The part where i'm stuck is changing the '^' with the number of mines surrounding it what my code does is return a 2d array but instead of numbers, I'm getting weird questions marks.</p>
  
  <p>here are my functions.</p>
  
  <pre class="lang-java prettyprint-override"><code>static char[][] calculatemines(char[][] h) {
      int height = h.length;
      int width = h[0].length;
  
      char[][] newh = new char[height][width];
      for (int i = 0; i &lt; newh.length; i++) {
          for (int j = 0; j &lt; newh[0].length; j++) {
              if(h[i][j]=='*') {
                  newh[i][j]='*';
              } else
                  newh[i][j]= (char) numberofmines(h,height,width);
          }
      }
  
      return newh;
  }
  </code></pre>
  
  <p>and this s the second function</p>
  
  <pre class="lang-java prettyprint-override"><code>private static int numberofmines(char[][] f, int height, int width) {
  
      int numberofmines = 0;
  
      for (int i = 0; i &lt; height; i++) {
          for (int j = 0; j &lt; width; j++) {
  
              int iStart = Math.max(0, i - 1);
              int iEnd = Math.min(height, i + 1);
  
              int jStart = Math.max(0, j - 1);
              int jEnd = Math.min(width, j + 1);
  
              for (int squareI = iStart; squareI &lt; iEnd; squareI++) {
                  for (int squareJ = jStart; squareJ &lt; jEnd; squareJ++) {
                      if (f[squareI][squareJ] == '*') {
                          numberofmines++;
                      }
                  }
              }
          }
      }
  
      return numberofmines;
  }
  </code></pre>
  
  <p>Thank you for all the help :)</p>