fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. private static int replace(int[] A, int n, int index, int product) {
  11. int remainingProduct = 1;
  12. if (index < n) {
  13. remainingProduct = replace(A, n, index + 1, product * A[index]);
  14. int tmp = A[index];
  15. A[index] = product * remainingProduct;
  16. remainingProduct *= tmp;
  17. }
  18. return remainingProduct;
  19. }
  20. public static void main(String[] args) {
  21. int[] A = {1, 2, 3, 4, 5};
  22. replace(A, A.length, 0, 1);
  23. for (int element : A) {
  24. System.out.printf("%d\t\t", element);
  25. }
  26. }
  27. }
Success #stdin #stdout 0.1s 28092KB
stdin
Standard input is empty
stdout
120		60		40		30		24