<awangdev>43. Multiply Strings_5.java
public String multiply(String num1, String num2) {
        if (num1 == null || num2 == null) {
            return "";
        } else if (num1.length() == 0 || num2.length() == 0) {
            return num1.length() == 0 ? num2 : num1;
        } else if (num1.equals("0") || num2.equals("0")) {
            return "0";
        }
        num1 = new StringBuffer(num1).reverse().toString();
        num2 = new StringBuffer(num2).reverse().toString();
     
        int[] product = new int[num1.length() + num2.length()];
        
        for (int i = 0; i < num1.length(); i++) {
        	int a = num1.charAt(i) - '0';
            for (int j = 0; j < num2.length(); j++) {
            	int b = num2.charAt(j) - '0';
                product[i + j] += a * b;
            }
        }
        
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < product.length; i++) {
           	int number = product[i] % 10;
           	int carrier = product[i] / 10;
           	sb.append(number);
            if (i < product.length - 1) {
                product[i + 1] += carrier;
            } 
        }
        sb.reverse();
        while (sb.length() > 0 && sb.charAt(0) == '0') {
        	sb.deleteCharAt(0);
        }

        return sb.toString();    
    }
public String var_0 ( String var_2 , String var_3 ) {
  if ( var_2 == null || var_3 == null ) {
    return "" ;
  }
  else if ( var_2 . length ( ) == 0 || var_3 . length ( ) == 0 ) {
    return var_2 . length ( ) == 0 ? var_3 : var_2 ;
  }
  else if ( var_2 . equals ( "0" ) || var_3 . equals ( "0" ) ) {
    return "0" ;
  }
  var_2 = new StringBuffer ( var_2 ) . reverse ( ) . toString ( ) ;
  var_3 = new StringBuffer ( var_3 ) . reverse ( ) . toString ( ) ;
  int [ ] var_13 = new int [ var_2 . length ( ) + var_3 . length ( ) ] ;
  for ( int var_14 = 0 ;
  var_14 < var_2 . length ( ) ;
  var_14 ++ ) {
    int var_17 = var_2 . charAt ( var_14 ) - '0' ;
    for ( int var_18 = 0 ;
    var_18 < var_3 . length ( ) ;
    var_18 ++ ) {
      int var_19 = var_3 . charAt ( var_18 ) - '0' ;
      var_13 [ var_14 + var_18 ] += var_17 * var_19 ;
    }
  }
  StringBuffer var_20 = new StringBuffer ( ) ;
  for ( int var_14 = 0 ;
  var_14 < var_13 . length ;
  var_14 ++ ) {
    int var_22 = var_13 [ var_14 ] % 10 ;
    int var_23 = var_13 [ var_14 ] / 10 ;
    var_20 . append ( var_22 ) ;
    if ( var_14 < var_13 . length - 1 ) {
      var_13 [ var_14 + 1 ] += var_23 ;
    }
  }
  var_20 . reverse ( ) ;
  while ( var_20 . length ( ) > 0 && var_20 . charAt ( 0 ) == '0' ) {
    var_20 . deleteCharAt ( 0 ) ;
  }
  return var_20 . toString ( ) ;
}
