// INPUT: "you shall not pass" // OUTPUT: "pass not shall you" String s[] = "you shall not pass".split(" "); String ans = ""; for (int i = s.length - 1; i >= 0; i--) { ans += s[i] + " "; } System.out.println(ans);