0
How to move punctuation
I am working on Pig Latin. In one of the rules, I have to move punctuation. Please give me some advice on how to move punctuation to the end of the translated word. This is my code so far. https://code.sololearn.com/cj85KNP32FI5
2 Answers
+ 6
String punctuation = "";
for (int i = str.length() - 1; i > 0; i--) {
if (!Character.isLetter(str.charAt(i))) {
punctuation = str.charAt(i) + punctuation;
} else {
break; // Found all punctuation
}
}
str = str.substring(0, str.length() - punctuation.length()); // Remove punctuation
// Convert str to pig latin
// Append punctuation to str
+ 1
Thank you!