Practice-It! logo

Exercise 6.7: wordWrap

Added by: Leslie Ferguson

NOTE: This problem seems to come from an oudated edition of the Building Java Programs textbook. Please make sure that you are solving the problem from the right edition of the textbook that you are using in your class. (Click here to jump to the current edition's version of this problem instead.)

Write a method called wordWrap that accepts a Scanner representing an input file as its parameter and outputs each line of the file to the console, word-wrapping all lines that are longer than 60 characters. For example, if a line contains 112 characters, the method should replace it with two lines: one containing the first 60 characters and another containing the final 52 characters. A line containing 217 characters should be wrapped into four lines: three of length 60 and a final line of length 37.

You must log in before you can solve this problem.

Log In

indent Re-indent

If you do not understand how to solve a problem or why your solution code doesn't work, please contact your TA or instructor.

If something seems wrong with the Practice-It system itself (errors, slow performance, incorrect problem descriptions/tests, etc.), please contact us.

Is there a problem?
Contact a Practice-It administrator.