public static void hist ( float [ ] data , int fmax ) { float [ ] hist = new float [ data . length ] ; // scale maximum float hmax = 0 ; for ( int i = 0 ; i < data . length ; i ++ ) { hmax = Math . max ( data [ i ] , hmax ) ; } float shrink = fmax / hmax ; for ( int i = 0 ; i < data . length ; i ++ ) { hist [ i ] = shrink * data [ i ] ; } NumberFormat nf = new DecimalFormat ( "00" ) ; String scale = "" ; for ( int i = 1 ; i < fmax / 10 + 1 ; i ++ ) { scale += " . " + i % 10 ; } System . out . println ( "x" + nf . format ( hmax / fmax ) + "\t0" + scale ) ; for ( int i = 0 ; i < hist . length ; i ++ ) { System . out . print ( i + "\t|" ) ; for ( int j = 0 ; j < Math . round ( hist [ i ] ) ; j ++ ) { if ( ( j + 1 ) % 10 == 0 ) System . out . print ( "]" ) ; else System . out . print ( "|" ) ; } System . out . println ( ) ; } }
Print table of multinomial data