Code below.
Code Link : https://ide.geeksforgeeks.org/ksLf4bvJPk
import java.util.*;
public class Main {
public static void product(int[] a, int n) {
int[] left = new int[n];
int[] right = new int[n];
int[] res = new int[n];
left[0] = 1;
right[n-1] = 1;
for(int i=1;i<n;i++) {
left[i] = left[i-1] * a[i-1];
}
for(int i=n-2;i>=0;i--) {
right[i] = right[i+1] * a[i+1];
}
for(int i=0;i<n;i++) {
res[i] = left[i] * right[i];
}
// print
for(int i=0;i<n;i++) {
System.out.print(res[i] + " ");
}
}
public static void main (String args[]) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] a = new int[n];
for(int i=0;i<n;i++) {
a[i] = scan.nextInt();
}
product(a, n);
}
}