fork(1) 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 = a.length - 1; i >= 0; i--) {
  25. for (int j = b.length - 1; j >= 0; j--) {
  26. int mul = r[i + j] + (a[i] * b[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 = a.length - 1; i >= 0; i--) {
  39. System.out.print(a[i]);
  40. }
  41. System.out.println();
  42. }
  43. }
Success #stdin #stdout 0.12s 36244KB
stdin
Standard input is empty
stdout
Case 10 9 
Case 29 9 
Case 30 9 
Case 10 8 
Case 28 8 
Case 39 8 
Case 18 26 
Case 26 26 
Case 311 26 
Case 10 16 
Case 26 16 
Case 37 16 
Case 16 33 
Case 23 33 
Case 310 33 
Case 10 24 
Case 24 24 
Case 35 24 
00111054