[SOLVED] Help With Word Scrambling Application

I was reading about the thing were if you scramble a word but keep the first and last letters in their correct positions, you are able to read it. I saw a link to a program that scrambled text in this way, so I decided to make my own. Nested for loops hurt my head, I keep forgetting what i'm trying to do, but I finished it and I think its fine. I use Netbeans 6.5 by the way. I tried to comment a bit so you can see what's going on, but I don't understand the error I'm getting. It compiles fine, but if I try running in Netbeans, Nothing happens. When I try in command prompt, I get this Error Message:(I didnt write all the folder names thats what the dots are)

Heres the code.. Please help I don't get why it's not working :confused:

Java Code:

package jmath.components;
public class WordScrambler {
private static int genRandomInteger(int range) { // range = word length
return (int)(Math.random() * (range - 3)) + 1; // makes random number
}
private static String scrambleWords(String txt) { // txt is the words
int[] used; /* the letter locations in the word that have already been used by a different scrambled character */
int location; // int to add to the used int[] when placing a letter
boolean already = false; // has the location in the word been taken?
char[] temp; // array to store the new scrambled word temporarily
int rand = 1; // random number
int range = 0; // length of word
String[] tokens = txt.split(" ,?!.()/\"\':;"); // the array of words & delims
/* **** 1 prob with this program is it removes all punctuation... */
String res = ""; // the returned result
for(int i = 0; i < tokens.length; i++) { // this loop cycles the words
if(tokens[i].length() <= 3) continue; // 3 or less letter word cant be scrambled
location = -1; // always starts off -1 for each word because it gets
/* incremented before each time something is added to int[] used so that first
is 0, next 1(location in the array) etc. */
range = tokens[i].length(); // the length of word
used = new int[range - 3]; // its -3 not -2 incase you thought that
/*** if you look down it goes through random positions in the word to scrambl
e the letters so a prob it takes a long time probably to get the right random num... */
temp = new char[range]; // temporary array to hold scrambled word
temp[0] = tokens[i].charAt(0); // first and last stay same so put
temp[range - 1] = tokens[i].charAt(range - 1); // them in right away
for(int j = 1; j < range - 1; j++) { // this loop cycles letters
while(rand != 0) { // this loop finds valid random position in word
rand = genRandomInteger(range);
for(int k = 0; k < used.length; k++) { // this sees if # is already used
if(rand == used[k]) {
already = true;
break;
}
}
if(already == true) continue; // then try anther num..
else {
used[++location] = rand; // add to used
break; // valid position found
}
}
temp[rand] = tokens[i].charAt(j); // put the letter in
} // next letter- back to top of loop
String s = new String(temp); // put the scambled word in String
res += s + " "; // add to returned result
}
return res;
}
public static void main(String[] args) {
String text = "Can You peoples Read This?"; // I made it short so it would go fast
System.out.println(scrambleWords(text)); // print it
}
}

So why won't it work?? as I was commenting i noticed 2 problems... 1 is not that horrible and probly easy solution: it removes punctuation, and... i know I'l use split method with boolean param that lets delimeters be counted as tokens then at start of word cycle loop i'l put an if .equals then a lot of || and repetition to put all the delims and then inside the if put a continue;. Ok that one solved, but the other problem is that This takes very long probably and because it keeps making random numbers until it's one that hasn't already been used, down to the point where theres one valid number out of the length of the word - 2 possible generated numbers.. if you have solutions to the error causing or the problem tell me please. And thankyou.

Tell me if you want a cool Java logo avatar like mine and I'll make you one.

no i changed the name after.. i might of put the error for the old name and the code for the new name, but i renamed after.
That has nothing to do with error. I tried the break label and it worked.. sort of.. but it got this output:

Java Code:

c id Ts e p a ?

And the text to be scrambled was this:"Can You peoples Read This?"... how did it get that?

Tell me if you want a cool Java logo avatar like mine and I'll make you one.

I found the problem... my split delimeters aren't working. It treats the whole text "Can You peoples Read This?" as 1 token.... Why? what did I do wrong? EDIT: Ok i tried making the delimeter just a space, i thought each char in the string of the split method would be a delimeter, but anyway, i made it just a space, and now it counted as 5 words, but the program is in endless loop somehow, not doing anything, still says running... heres the code again so you can see what I've done.

Forget the renaming thing, I just decided after that Scrambler sounds better. The endless loop isnt fixed, read my post, When i got it to treat each word as a seperate word (but then i can only use a space as delimeter), it endless loops again. I don't get what you mean with packages causing errors.. The scrambling i wanted was like this:
"Can You peoples Read This?" would be something like this:
"Can You plpoees Raed Tihs?"
Each word scrambled by individually, but keeping the first and last letter in the right place.
As in each word stays in the right place, just letters in between the first and last letters(thats why 3 or less letter words can't get scrambled) get mixed up.
EDIT: Ok even if i make the text 1 word, so that it won't endless loop, for the word "Equivalent" I got:
"En a t " ... it has a bunch of spaces and missing letters.. same as original word, but last letter in wrong spot.. every time the t is in second last position, with a space after it. Somhow alot of the letters don't get assigned... :confused:
EDIT:Ok nevermind i got mixed up itdoes put the first and last letters in their correct positions, but why does it not get all the letters? it missed more then half the letters in the middle and leaves them as whitespace. Here are my priorities:
1. Get the 1 word to work so that all the letters in the middle get placed in the scrambled word.
2. Make it work with lots of words so that it won't go in endless loop when more then 1 word(don't know why it does that)
3. Make the delimeters work, For some reason i have to just put a space, i don't know how to make more then one thing a possible delimeter....actually i think i figured it out.. anyway..
4. Make it more effiecient. now it goes through random numbers until it finds one that isnt used, takes longer.
EDIT: ok cross out #3 im using stringtokenizer instead so delimiters can be counted, punctuation not removed, and it uses ,.!?()-/&:;\" as delimiters not just a space. And delimeters won't be scrambled because they're all 1 character long and it doesnt scramble unless word is 4 or more characters long. But it still endless loops if theres more then 1 token, and if it's 1 token then it doesnt put in all the letters.. I'll show you the code so far, please help.

oh thanks for poiting that out.. i forgot to make it add to the result.. but still that hasn't been causing aany problems.. i'll go change it now.. thanks for looking at it too. In the code i removed the addidng space from

Java Code:

res += s + " ";
I changed it to
res += s;

because now whitespace(and all delimiters) are counted as tokens.
And now I changed this:

Ok I stared at the loops for a while and changed some things that didn't make sense before. Also made stuff not static. But now it endless loops even with just 1 word.. Here is the code so far, first though here is what I need help on(and help in order, I can't do number 3 until 1 and 2 are done for example):1. Make 1 word work (scramble correctly - scramble letters inside word but keep first and last letters in the right spots e.g. Parentheses -> Ptehesnares, goal -> gaol, etc.)2. Make it work with a lot of tokens, get rid of endless loop(hopefully solving #1 will also solve this one)3. More efficient, right now it makes random numbers, word length - 2 different possibilities , down to the point where only one of the possibilities will be accepted.4. uhm.. Make it Scramble text from a .txt document.
Heres Code.