logo CodeStepByStep logo

productOfOthers

Language/Type: Java arrays traversals

Write a method named productOfOthers that accepts an array of integers a as its parameter and returns a new array where each element at index i stores the product of all elements in a excluding a[i]. For example, if the array a stores {1, 4, 3, 4, 2}, the call of productOfOthers(a) should return {96, 24, 32, 24, 48}.

You may assume that the product of all elements in the array is within the domain of integers (type int).

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.