fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4. class Main
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String str = "quick brown fox jumps over the lazy dog";
  9. List<String> res = new ArrayList<String>();
  10. String last = null;
  11. String[] tok = str.split(" ");
  12. for (int i = tok.length-1 ; i >= 0 ; i--) {
  13. if (last == null) {
  14. last = tok[i];
  15. } else {
  16. last = tok[i] + " " + last;
  17. }
  18. res.add(last);
  19. }
  20. for (String s : res) {
  21. System.out.println(s);
  22. }
  23. }
  24. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
dog
lazy dog
the lazy dog
over the lazy dog
jumps over the lazy dog
fox jumps over the lazy dog
brown fox jumps over the lazy dog
quick brown fox jumps over the lazy dog