fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.Stack;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main(String[] args) {
  12. String input = "Hi there Mr.Dog!";
  13.  
  14. for(String word : input.split(" ")){
  15. System.out.print(reverse(word + " "));
  16. }
  17. }
  18.  
  19. private static String reverse(String word){
  20. Stack<Character> stack = new Stack<>();
  21.  
  22. for(char c : word.toCharArray()){
  23. stack.push(c);
  24. }
  25.  
  26. String result = "";
  27. while(!stack.isEmpty()){
  28. result += stack.pop();
  29. }
  30.  
  31. return result;
  32. }
  33. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
 iH ereht !goD.rM