private String printOFormat(String sx){
  int nLeadingZeros=0;
  int nBlanks=0;
  if (sx.equals("0") && precisionSet && precision == 0)   sx="";
  if (precisionSet)   nLeadingZeros=precision - sx.length();
  if (alternateForm)   nLeadingZeros++;
  if (nLeadingZeros < 0)   nLeadingZeros=0;
  if (fieldWidthSet)   nBlanks=fieldWidth - nLeadingZeros - sx.length();
  if (nBlanks < 0)   nBlanks=0;
  int n=nLeadingZeros + sx.length() + nBlanks;
  char[] ca=new char[n];
  int i;
  if (leftJustify) {
    for (i=0; i < nLeadingZeros; 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 (i=0; i < nBlanks; i++)     ca[i]='0';
 else     for (i=0; i < nBlanks; i++)     ca[i]=' ';
    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];
  }
  return new String(ca);
}

private String printOFormat ( String sx ) { int nLeadingZeros = 0 ; int nBlanks = 0 ; if ( sx . equals ( "0" ) && precisionSet && precision == 0 ) sx = "" ; if ( precisionSet ) nLeadingZeros = precision - sx . length ( ) ; if ( alternateForm ) nLeadingZeros ++ ; if ( nLeadingZeros < 0 ) nLeadingZeros = 0 ; if ( fieldWidthSet ) nBlanks = fieldWidth - nLeadingZeros - sx . length ( ) ; if ( nBlanks < 0 ) nBlanks = 0 ; int n = nLeadingZeros + sx . length ( ) + nBlanks ; char [ ] ca = new char [ n ] ; int i ; if ( leftJustify ) { for ( i = 0 ; i < nLeadingZeros ; 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 ( i = 0 ; i < nBlanks ; i ++ ) ca [ i ] = '0' ; else for ( i = 0 ; i < nBlanks ; i ++ ) ca [ i ] = ' ' ; 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 ] ; } return new String ( ca ) ; }
utility method for formatting using the o conversion character .
