Martin2203's picture
Add data
55f0e26
raw
history blame contribute delete
812 Bytes
package correct_java_programs;
import java.util.*;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author derricklin
*/
public class WRAP {
public static void main(String[] args) {
System.out.println("abc".lastIndexOf("c",30));
}
public static ArrayList<String> wrap(String text, int cols) {
ArrayList<String> lines = new ArrayList<String>();
String line;
while (text.length() > cols) {
int end = text.lastIndexOf(" ", cols); // off by one?
if (end == -1) {
end = cols;
}
line = text.substring(0,end);
text = text.substring(end);
lines.add(line);
}
lines.add(text);
return lines;
}
}