title: Duplicating every second row and every second column of a 2d array in java
body: <p>I have a 2d array of ints
  I need to duplicate every second row and every second column of the 2d array as follows (overwriting the existing value, not creating a new column/row) using java:</p>
  
  <p><a href="https://vgy.me/7HI3Yz.png" rel="nofollow noreferrer">example</a> </p>
  
  <p>Current approach</p>
  
  <pre><code>     for(int i = 0; i &lt; result.get(z).getWidth()-2; i+=1)
      {   for(int j = 0; j &lt; result.get(z).getHeight()-2; j+=1)
      {   
          x[i+1][j] = result.get(z).getRGB(i, j);
          x[i][j+1] = result.get(z).getRGB(i, j);
          x[i+1][j+1] = result.get(z).getRGB(i, j);
  
  
  
  
      }
  
  }
  </code></pre>