Does this has a solution?

This problem is from the book "Building Java-Programs: A back to basis approach" Chapter 6:

9. 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.

(This one is fine and I already did it. The issue comes with the next one which elaborates on this previous one)

10. Modify the preceding wordWrap method so that it outputs the newly wrapped text back into the original file. (Be careful—don’t output into a file while you are reading it!) Also, modify it to use a class constant for the maximum line length rather than hard-coding 60.

The main thing is that if I cannot seem to distinguish between a sentence that was cut before if said sentence had exactly 60 characters.

ex: How to distinguish between these two scenarios?

Original text:

Line with 60 characters New line with less than 60 characters.


Line with more than 60 characters but less than 120 characters.

The first one will be broken into 2 lines (one with 60 and another one with less than 60). The second line will also be broken into 2 lines (one with 60 and another one with less than 60) How can I distinguish the two scenarios then? What type of algorithm would you use?

Thanks everyone in advance.