I was trying to solve this excercice but got little bug. I have to reformat this text with spaces and length of every lines must be not exceed 60 characters.
"Java was originally developed by James Gosling at Sun Microsystems (which has since been acquired by Oracle) and released in 1995 as a core component of Sun Microsystems' Java platform."
There is my code:
static String text;
public String reformatLines(String text) {
if(text == null || text.isEmpty());
return text;
}
public static void main(String[] args) {
String text = "Java was originally developed by James Gosling at Sun Microsystems (which has since been acquired by Oracle) and released in 1995 as a core component of Sun Microsystems' Java platform.";
String str = text.replaceAll("[\n]{2,}", " ");
int length = 60;
String jump = new String();
while(text.length()>length){
int jp = str.lastIndexOf(" ", length);
jump = jump.concat(str.substring(0, jp));
jump = jump.concat("\n");
str = str.substring(jp, str.length());
}
}
}
I actually, have no idea what to do...