Question: I have an `int[]` 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.

So for example: 

* Array1: `{4,3,5,7}`
* Array2: `{3*5*7, 4*5*7, 4*3*7, 4*3*5} = {105, 140, 84, 60}`

Here's what I have:

```
public static int[] multiplyArrayValues (int [] values) {

    int array[] = new int[values.length];

    for (int y = 0; y < array.length; y++) {
        array[y] = 1;
    }

    /*for (int i = 0; i < array.length; i++) {      // wrong                        
        for (int z = 0; z < x; z++) {                           
            if (z != i) {                                                   
                array[i] = array[i] * values[z];                                        
            }               
        }           
    }*/

    return array;
}  

```

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.

Answer: 
First multiply all the elements from the array. And then loop over all elements and divide the previously computed multiplication with current item.
You can multiply all numbers and save it a variable(say product) , now iterate over the array using single loop and divide the product by number at each index(product/a[i]).

But since you are using integer , if the size of array is huge and also the array values is big , the product might overflow int.

Consider using Big integer i would say.