``java
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner inputReader = new Scanner(System.in);
String line = inputReader.nextLine();
String[] unconvertedValues = line.split(" ");
int numWords = Integer.parseInt(unconvertedValues[0]);
int maxChar = Integer.parseInt(unconvertedValues[1]);
line = inputReader.nextLine();
String[] words = line.split(" ");
String linePrint = "";
int currentChar = 0;
for (int i = 0; i < numWords; i++) {
if ((currentChar + words[i].length()) <= maxChar) {
currentChar += words[i].length();
linePrint += words[i] + " ";
}else{
System.out.println(linePrint);
currentChar = 0;
linePrint = "";
i--;
}
}
System.out.println(linePrint);
}
}
I submitted my code here [Link to CPI bronze class](https://usaco.guide/groups/d7eYGfddXq3m2trXG2xt/post/ZkhTvlw0KgyHrqQ69LD1/problems/iHaZTUqAEQqz7LzrAojM)
INPUT:
10 7
hello my name is Bessie and this is my essay
OUTPUT:
hello my
name is
Bessie
and this
is my
essay