public void print(PrintWriter output,NumberFormat format,int width){
  output.println();
  for (int i=0; i < m; i++) {
    for (int j=0; j < n; j++) {
      String s=format.format(A[i][j]);
      int padding=Math.max(1,width - s.length());
      for (int k=0; k < padding; k++)       output.print(' ');
      output.print(s);
    }
    output.println();
  }
  output.println();
}

public void print ( PrintWriter output , NumberFormat format , int width ) { output . println ( ) ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { String s = format . format ( A [ i ] [ j ] ) ; int padding = Math . max ( 1 , width - s . length ( ) ) ; for ( int k = 0 ; k < padding ; k ++ ) output . print ( ' ' ) ; output . print ( s ) ; } output . println ( ) ; } output . println ( ) ; }
print the matrix to the output stream . line the elements up in columns . use the format object , and right justify within columns of width characters . note that is the matrix is to be read back in , you probably will want to use a numberformat that is set to us locale .
