title: Java - Multiply Array Values into another Array
body: <p>I have an <code>int[]</code> array with x values (x can be defined by the user), the values are random ints between 1 and 9. Now I want to create another Array with the same amount of values, and each value of the new Array is the product of all values from the other Array, except the same index.</p>
  
  <p>So for example:  </p>
  
  <ul>
  <li>Array1: <code>{4,3,5,7}</code></li>
  <li>Array2: <code>{3*5*7, 4*5*7, 4*3*7, 4*3*5} = {105, 140, 84, 60}</code></li>
  </ul>
  
  <p>Here's what I have:</p>
  
  <pre><code>public static int[] multiplyArrayValues (int [] values) {
  
      int array[] = new int[values.length];
  
      for (int y = 0; y &lt; array.length; y++) {
          array[y] = 1;
      }
  
      /*for (int i = 0; i &lt; array.length; i++) {      // wrong                        
          for (int z = 0; z &lt; x; z++) {                           
              if (z != i) {                                                   
                  array[i] = array[i] * values[z];                                        
              }               
          }           
      }*/
  
      return array;
  }  
  </code></pre>
  
  <p>The difficulty is, I have to avoid for-loops in for-loops for performance. Which is why that one block is commented-out.  Dividing is not allowed.  </p>