where do I put a System.out.println statement
The entire output is built in a single string that is not printed until the end, so adding System.out.println statements in the line loop won't help. You can add line breaks to the string by doing:
out += "\n";
Or, at the end of the body of your line loop, print the current line, and reset the buffer for the next line:
System.out.println(out);
out = "";
Using a String for the output buffer is not efficient by the way. String is immutable, so every +
statement is copying and duplicating all of the previous characters to create a new object, every time. Consider declaring out
as a StringBuilder rather than a String. Then you can add to it with the .append()
method and it will not copy all the text every time because a StringBuilder is mutable.