private static void divide(int[] n1,int[] n2,int[] quotient,int[] remainder){
  if (isZero(n2)) {
    throw new ArithmeticException("Divide by Zero");
  }
  clear(remainder);
  clear(quotient);
  if (compareTo(n2,n1) > 0) {
    int idx=remainder.length - 1;
    for (int i=0; i < n1.length; i++) {
      remainder[idx--]=n1[i];
    }
    return;
  }
  n1=reduce(n1);
  n2=reduce(n2);
  while (compareTo(n2,0,n2.length,n1,0) > 0) {
    n2=expand(n2);
  }
  String result=subProcess(n1,n2);
  int idx=result.indexOf("+");
  if (idx == -1) {
    for (int i=0; i < quotient.length; i++) {
      quotient[i]=0;
    }
    pack(remainder,result);
  }
 else {
    pack(quotient,result.substring(0,idx));
    pack(remainder,result.substring(idx + 1));
  }
}

private static void divide ( int [ ] n1 , int [ ] n2 , int [ ] quotient , int [ ] remainder ) { if ( isZero ( n2 ) ) { throw new ArithmeticException ( "Divide by Zero" ) ; } clear ( remainder ) ; clear ( quotient ) ; if ( compareTo ( n2 , n1 ) > 0 ) { int idx = remainder . length - 1 ; for ( int i = 0 ; i < n1 . length ; i ++ ) { remainder [ idx -- ] = n1 [ i ] ; } return ; } n1 = reduce ( n1 ) ; n2 = reduce ( n2 ) ; while ( compareTo ( n2 , 0 , n2 . length , n1 , 0 ) > 0 ) { n2 = expand ( n2 ) ; } String result = subProcess ( n1 , n2 ) ; int idx = result . indexOf ( "+" ) ; if ( idx == - 1 ) { for ( int i = 0 ; i < quotient . length ; i ++ ) { quotient [ i ] = 0 ; } pack ( remainder , result ) ; } else { pack ( quotient , result . substring ( 0 , idx ) ) ; pack ( remainder , result . substring ( idx + 1 ) ) ; } }
return n1 / n2 as result and quotient . note that n1 and n2 are unaffected . work this as reducing problem into smaller problems , from which the result is generated . take 0074 divide into 6928 1 . 074 divide into 692 ( 9 ) 2 . 074 divide into 268 ( 3 ) 3 . 74 divide into 46 ( + 46 )
