+ 1
I want to reverse the words of a sentence, without reversing the letters in java.
input:"I am a man" output:"man a am I"
2 Respostas
+ 1
You could try putting each word as it's own element in an array and then using a for loop to iterate through the array in reverse and printing each word whilst doing so.
Some psuedocode:
String arr [] = ["I","am","a,"man"];
for (int i = arr.length ()-1;i > 0;i--){
System.out.println (arr [i]);
If you wanted to implement this on a more broader scale (as in any string), you could create a piece of code that iteratively puts each word into an array. For the specific string, though, that should work.
+ 1
Hi, you can check your answer here,
http://www.vsit.in/vsit-blog/java-program-to-reverse-words-in-a-sentence/