re: Java Daily Coding Problem #002 VIEW POST

FULL DISCUSSION
 

Java 8:

   int[] array = { 1, 2, 3, 4, 5 };
    final int product = Arrays.stream(array)
            .reduce((x,y) -> x * y )
            .getAsInt();

    int[] newArray = Arrays.stream(array)
            .map(x -> product / x)
            .toArray();

    System.out.println(Arrays.toString(newArray));

Fails for elements with a 0, obviously, could be worked around with filtering.

code of conduct - report abuse