umm... i am a new java programmer so I can't think of an easy way....

I am writing a piglatin translator(yes a common lab I am sure) but the puncuation aspect is tricky for me, here's my method thus far:

public static StringBuffer insert_punc(StringBuffer new_word, int[] punc_loc)

{String character = "";

int loc = 0;

for(int i = 1; i < punc_loc.length; i = i + 2)

{loc = punc_loc;

new_word.insert(loc, punc_loc[i+1]);

}

return new_word;

}

public static int[] find_punc(StringBuffer new_word)

{char[] punc = {'.' , ',' , ';' , '?' ,'!', ':'};

int[] punc_loc = new int[30];

int i = 0;

for(int count = 0; count < new_word.length(); count++) //cycles through the word

{for(int count2 = 0; count2 < 5; count2++) //cycle through punctuation

{if(new_word.charAt(count) == punc[count2]) //if the character is a punctuation character

{System.out.println("I: " + i);

System.out.print("Location: " + count);

punc_loc[0] = punc[count2]; //then add punctuation symbol

punc_loc[1] = count;// and it's location to array punc_loc

System.out.println(" Punc Char: " + punc[count2]);

}

}

}

System.out.println(punc_loc[0]);

System.out.println(punc_loc[1]);

return punc_loc;

}

the method names are self-explanatory( I am finding the puncuation locations, and what the character is at that point and putting it in a standary array) I just have been working on this too long and could use any help. Thx a lot :)

[1533 byte] By [ryudena] at [2007-10-3 7:49:57]
# 1
When you post code, please wrap it in [code][/code] tags so it's legible.Do you have a specific question?
paulcwa at 2007-7-15 2:51:46 > top of Java-index,Java Essentials,New To Java...
# 2
yeah, sorry about that... I wanted to know if any1 had any suggestions on why the code isn't storing index of the puncuation correctly. I think that at punc_loc[0] it is storing as 33 for the first puncuation location some reason... no idea
ryudena at 2007-7-15 2:51:46 > top of Java-index,Java Essentials,New To Java...
# 3
Well, if you want us to read your code you should post it with the code tags so we can read it.Can you explain what your program is supposed to be doing, and what it's doing instead?
paulcwa at 2007-7-15 2:51:46 > top of Java-index,Java Essentials,New To Java...
# 4

public static StringBuffer insert_punc(StringBuffer new_word, int[] punc_loc)

{ String character = "";

int loc = 0;

for(int i = 1; i < punc_loc.length; i = i + 2)

{ loc = punc_loc;

new_word.insert(loc, punc_loc[i+1]);

}

return new_word;

}

public static int[] find_punc(StringBuffer new_word)

{ char[] punc = {'.' , ',' , ';' , '?' ,'!', ':'};

int[] punc_loc = new int[30];

int i = 0;

for(int count = 0; count < new_word.length(); count++) //cycles through the word

{ for(int count2 = 0; count2 < 5; count2++) //cycle through punctuation

{ if(new_word.charAt(count) == punc[count2]) //if the character is a punctuation character

{ System.out.println(" I: " + i);

System.out.print(" Location: " + count);

punc_loc[0] = punc[count2]; //then add punctuation symbol

punc_loc[1] = count; // and it's location to array punc_loc

System.out.println(" Punc Char: " + punc[count2]);

}

}

}

System.out.println(punc_loc[0]);

System.out.println(punc_loc[1]);

return punc_loc;

}

ok... I am making a program to translate a word into piglatin, keeping punctuation of the word in tact. StringBuffer new_word is the word that is received from the user, punc_loc is an array that I want to have store the location followed by the character at each location.

For example: if i was to enter "Bill's!"

I would want the array to look like:

[4,"'", 6, "!"]

However, in this example my code is returning the incorrect index(I think it was 33) So my question is; why is it returning an incorrect value? Where did I mess up at?

ryudena at 2007-7-15 2:51:46 > top of Java-index,Java Essentials,New To Java...
# 5

oops... This change

public static StringBuffer insert_punc(StringBuffer new_word, int[] punc_loc)

...

...

for(int i = 1; i < punc_loc.length; i = i + 2)

{ loc = punc_loc;

new_word.insert(loc, punc_loc[i+1]);

}

the 2nd line should be

loc = punc_loc[i];

PS

The insert_punc method was just put posted to show how the program works(kinda long to post whole program). Again, all i want help with is to figure out why my code isn't storing the index into the array correctly

ryudena at 2007-7-15 2:51:46 > top of Java-index,Java Essentials,New To Java...
# 6
There are a lot of parathesis problems in your code. Look through it and correct them. It should solve your problem.
zadoka at 2007-7-15 2:51:46 > top of Java-index,Java Essentials,New To Java...