int n = (17 - line1.length())/2; System.out.print("|"); System.out.printf("%"+n+"s", ""); System.out.print(line1); for(int spaceAfter1 = 0; spaceAfter1 < n; spaceAfter1++){ System.out.print(" "); } System.out.print("|");