Reverse Sentence word by word
while(n-- >0) {
String s = br.readLine();
for(char c:s.toCharArray()) {
//System.out.printf("c : %c",c);
//System.out.println();
if(c == ' ') {
while(!st.isEmpty()) {
System.out.print(st.pop());
}
System.out.print(c);
}
else {
st.push(c);
}
}
}Last updated