private String printXFormat(String sx){
  int nLeadingZeros=0;
  int nBlanks=0;
  if (sx.equals("0") && precisionSet && precision == 0)   sx="";
  if (precisionSet)   nLeadingZeros=precision - sx.length();
  if (nLeadingZeros < 0)   nLeadingZeros=0;
  if (fieldWidthSet) {
    nBlanks=fieldWidth - nLeadingZeros - sx.length();
    if (alternateForm)     nBlanks=nBlanks - 2;
  }
  if (nBlanks < 0)   nBlanks=0;
  int n=0;
  if (alternateForm)   n+=2;
  n+=nLeadingZeros;
  n+=sx.length();
  n+=nBlanks;
  char[] ca=new char[n];
  int i=0;
  if (leftJustify) {
    if (alternateForm) {
      ca[i++]='0';
      ca[i++]='x';
    }
    for (int j=0; j < nLeadingZeros; j++, i++)     ca[i]='0';
    char[] csx=sx.toCharArray();
    for (int j=0; j < csx.length; j++, i++)     ca[i]=csx[j];
    for (int j=0; j < nBlanks; j++, i++)     ca[i]=' ';
  }
 else {
    if (!leadingZeros)     for (int j=0; j < nBlanks; j++, i++)     ca[i]=' ';
    if (alternateForm) {
      ca[i++]='0';
      ca[i++]='x';
    }
    if (leadingZeros)     for (int j=0; j < nBlanks; j++, i++)     ca[i]='0';
    for (int j=0; j < nLeadingZeros; j++, i++)     ca[i]='0';
    char[] csx=sx.toCharArray();
    for (int j=0; j < csx.length; j++, i++)     ca[i]=csx[j];
  }
  String caReturn=new String(ca);
  if (conversionCharacter == 'X')   caReturn=caReturn.toUpperCase();
  return caReturn;
}

private String printXFormat ( String sx ) { int nLeadingZeros = 0 ; int nBlanks = 0 ; if ( sx . equals ( "0" ) && precisionSet && precision == 0 ) sx = "" ; if ( precisionSet ) nLeadingZeros = precision - sx . length ( ) ; if ( nLeadingZeros < 0 ) nLeadingZeros = 0 ; if ( fieldWidthSet ) { nBlanks = fieldWidth - nLeadingZeros - sx . length ( ) ; if ( alternateForm ) nBlanks = nBlanks - 2 ; } if ( nBlanks < 0 ) nBlanks = 0 ; int n = 0 ; if ( alternateForm ) n += 2 ; n += nLeadingZeros ; n += sx . length ( ) ; n += nBlanks ; char [ ] ca = new char [ n ] ; int i = 0 ; if ( leftJustify ) { if ( alternateForm ) { ca [ i ++ ] = '0' ; ca [ i ++ ] = 'x' ; } for ( int j = 0 ; j < nLeadingZeros ; j ++ , i ++ ) ca [ i ] = '0' ; char [ ] csx = sx . toCharArray ( ) ; for ( int j = 0 ; j < csx . length ; j ++ , i ++ ) ca [ i ] = csx [ j ] ; for ( int j = 0 ; j < nBlanks ; j ++ , i ++ ) ca [ i ] = ' ' ; } else { if ( ! leadingZeros ) for ( int j = 0 ; j < nBlanks ; j ++ , i ++ ) ca [ i ] = ' ' ; if ( alternateForm ) { ca [ i ++ ] = '0' ; ca [ i ++ ] = 'x' ; } if ( leadingZeros ) for ( int j = 0 ; j < nBlanks ; j ++ , i ++ ) ca [ i ] = '0' ; for ( int j = 0 ; j < nLeadingZeros ; j ++ , i ++ ) ca [ i ] = '0' ; char [ ] csx = sx . toCharArray ( ) ; for ( int j = 0 ; j < csx . length ; j ++ , i ++ ) ca [ i ] = csx [ j ] ; } String caReturn = new String ( ca ) ; if ( conversionCharacter == 'X' ) caReturn = caReturn . toUpperCase ( ) ; return caReturn ; }
utility method for formatting using the x conversion character .
