Thread: Word Scramble
View Single Post
  #4 (permalink)  
Old 11-16-2007, 09:56 AM
hardwired's Avatar
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
So, something like this:
Code:
System.out.printf("s = %s%n", s);
while(s.length() > 0) {
    int pos = generator.nextInt(s.length());
    if(pos == 0)
        s = s.substring(1);
    else if(pos == s.length()-1)
        s = s.substring(0, pos);
    else
        s = s.substring(0, pos) + s.substring(pos+1, s.length()-1);
    System.out.printf("pos = %d  s = %s%n", pos, s);
}
System.out.println("s = " + s);
Reply With Quote