2
I have a code I made to invert a String, but it does not meet what I need. I need it to convert the order of the characters of each sentence.
For example: He converts "Hi guys!" into "! laossep Io". And what I need is for him to convert to "Io! laossep".
My code:
public class ex1 {
public static void main(String[] args) {
String palavra = "Abobora Vermelha";
String resultado="";
for(int x = palavra.length() -1;x>=0;x--){
resultado = resultado + palavra.charAt(x);
}
System.out.println(resultado);
}
}
Possible duplicate of How to Invert a String?
– Marconi
@Marconi’s not a duplicate of that one. This other question is to invert the phrase as a whole, something that the OP was already doing, but the problem here is to invert only the words individually without reversing their order within the sentence. It’s a very similar and well-connected problem, but it’s different.
– Victor Stafusa