reverse sentence in java

Solutions on MaxInterview for reverse sentence in java by the best coders in the world

showing results for - "reverse sentence in java"
Mae
24 Jan 2020
1// INPUT: "you shall not pass"
2// OUTPUT: "pass not shall you"
3  
4String s[] = "you shall not pass".split(" "); 
5String ans = ""; 
6for (int i = s.length - 1; i >= 0; i--) {
7  ans += s[i] + " ";
8}
9System.out.println(ans);