You'll need to hold all the lines you read from standard input in memory before you can output any of them because you need to know the length of the longest line to size the box. Use an ArrayList to hold the lines. My solution has a method 'static String repl(char c, int n)' that returns a String that is n copies of the character c. For the empty-input case my solution simply returns from main. An alternative is to call System.exit(0).