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. public static void main(String[] args) {
  11.  
  12. int[] a = new int[]{3, 2, 1};
  13. int[] b = new int[]{8, 9};
  14. int[] rMultiplicacion = multiplicar(a, b);
  15. toString(rMultiplicacion);
  16. }
  17.  
  18. public static int[] multiplicar(int[] a, int[] b) {
  19. int[] r = new int[a.length + b.length + 1];
  20. for (int i = 0; i < r.length; i++) {
  21. r[i] = 0;
  22. }
  23.  
  24. for (int i = 0; i <=b.length-1; i++) {
  25. for (int j = a.length - 1; j >= 0; j--) {
  26. int mul = r[i + j] + (b[i] * a[j]);
  27. System.out.println("Case 1 " + r[i + j] + " " + mul + " ");
  28. r[i + j] = mul % 10;
  29. System.out.println("Case 2 " + r[i + j] + " " + mul + " ");
  30. r[i + j + 1] += mul / 10;
  31. System.out.println("Case 3 " + r[i + j + 1] + " " + mul + " ");
  32. }
  33. }
  34. return r;
  35. }
  36.  
  37. public static void toString(int[] a) {
  38. for (int i = 0; i <= a.length-1; i++) {
  39. System.out.print(a[i]);
  40. }
  41. System.out.println();
  42. }
  43. }
Success #stdin #stdout 0.11s 36220KB
stdin
Standard input is empty
stdout
Case 1  0 8 
Case 2  8 8 
Case 3  0 8 
Case 1  0 16 
Case 2  6 16 
Case 3  9 16 
Case 1  0 24 
Case 2  4 24 
Case 3  8 24 
Case 1  0 9 
Case 2  9 9 
Case 3  0 9 
Case 1  9 27 
Case 2  7 27 
Case 3  11 27 
Case 1  8 35 
Case 2  5 35 
Case 3  10 35 
45101100