For a given string sentence, reverse it.
/*
For a given string sentence, reverse it.
Input : Hello World
Output : Dlorw Olleh
Input: How Are You Doing Today
Output: Yadot Ginod Uoy Era Woh
*/
public class ReverseToString{
public static void main(String[] args) {
String inp = "how are you doing today?";
String temp = "";
boolean firstWord = false;
for (int i = inp.length() - 1; i >= 0; i--) {
if (firstWord == false) {
temp = temp + String.valueOf(inp.charAt(i)).toUpperCase();
firstWord = true;
} else if (String.valueOf(inp.charAt(i)).equals(" ")) {
temp = temp +" "+String.valueOf(inp.charAt(i - 1)).toUpperCase();
i = i - 1;
} else {
temp = temp + String.valueOf(inp.charAt(i)).toLowerCase();
}
}
System.out.println("The result is "+temp);
}
}
/*
Input:
how are you doing today?
Ouput:
?yadot Gniod Uoy Era Woh
*/