public class StringReverse {
public static void main(String[] args) {
StringReverse sr =new StringReverse();
String output=sr.reverse("reverse this string");
String substring="";
for(int i=0;i<=output.length();i++)
{
if(i==output.length()){
System.out.print(sr.reverse(substring));
substring="";
}else if(output.charAt(i)==' ' ){
System.out.print(sr.reverse(substring+" "));
substring="";
}
if(i<output.length())
{
substring+=output.charAt(i);}
}
}
public String reverse(String str){
char[] value=str.toCharArray();
int count=str.length();
int n = count - 1;
for (int j = (n-1) >> 1; j >= 0; --j) {
char temp = value[j];
value[j] = value[n - j];
value[n - j] = temp;
}
return new String(value);
}
}