Hi I've been head banging on this simple method.

**The goal:** is to create a new line after the width provided. E.g. if the width is 20 that means after 15 chars create a new line. Although there is Wordwrap.Utils to achieve this. I wanted to do this manually.

**The Problem:** is that the output is working however, if a word in the sentence exceeds the 15 characters it is chopped off and a new line is created. E.G. 
`Hi my name is J
immy and I love
 programming.`

As you can see the word 'Jimmy' is chopped off.

**The Question:** is how can I ensure that if a word makes the sentence more than 15 characters, create a new line before the word rather than chopping it of? So the output becomes:

`Hi my name is
Jimmy and I
love
programming.`

The Class is Below:

```
public class Test {

public static void main(String[] args){

    String txt = "Hi my name is Jimmy and I love programming.";
    int width = 15;

    System.out.println(lineLength(txt, width));

}

public static String lineLength(String str, int width) {
    StringBuilder sb = new StringBuilder();

    while(true) {
        if(str.length() <= width) {
            sb.append(str);
            break;
        }

        sb.append(str.substring(0, width));
        sb.append("\n");
        str = str.substring(width);
    }

    return sb.toString();
}
}

```