I want this sentence to out like . What is wrong here because it give me
java.lang.ArrayIndexOutOfBoundsException
package first;
import org.apache.commons.lang.RandomStringUtils;
public class reverseString2 {
public static void main(String []args){
String str = "The student so lazy";
String[] split = str.split(" ");
String middle = null;
StringBuilder output = new StringBuilder();
for (String s : split) {
middle = s.substring(1, s.length()-1 );
s = s.replace(middle,RandomStringUtils.random(5, middle));
output.append(s + " ");
}
System.out.println(output.toString());
}
}
You need to copy and paste your exact stack trace.
I wrote my own random method, because I don’t have the the best setup on this machine, and here’s what I got:
result:
Link http://ideone.com/5flnU