protected void printPi ( final String piString ) { System . out . print ( "\npi = " + piString . substring ( 0 , 2 ) ) ; int index = 2 ; int line = 0 ; int group = 0 ; final int length = piString . length ( ) ; // Loop for each group of 5 digits while ( index + 5 < length ) { System . out . print ( piString . substring ( index , index + 5 ) + " " ) ; index += 5 ; // End of line after 10 groups. if ( ++ group == 10 ) { System . out . println ( ) ; // Print a blank line after 10 lines. if ( ++ line == 10 ) { System . out . println ( ) ; line = 0 ; } System . out . print ( " " ) ; group = 0 ; } } // Print the last partial line. if ( index < length ) { System . out . println ( piString . substring ( index ) ) ; } }
Print the string containing the digits of pi .