public static String centre ( String string , int size , char padding ) { if ( string == null || size <= string . length ( ) ) { return string ; } StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < ( size - string . length ( ) ) / 2 ; i ++ ) { sb . append ( padding ) ; } sb . append ( string ) ; while ( sb . length ( ) < size ) { sb . append ( padding ) ; } return sb . toString ( ) ; }
Formats an output string by centering the given input string and padding it with the given character .