Hello
I want to do reverse each word of the String
example if input String is "Hello World" then the output should be "olleH dlroW"
i Have tried this far
I want to do reverse each word of the String
example if input String is "Hello World" then the output should be "olleH dlroW"
i Have tried this far
Code:
class g
{
static String s="Hello World Hello World";
static int last=s.lastIndexOf(' ');
static String tempS;
public static void start(int count)throws Exception
{
if(count!=last)
{
tempS+=reverse(s.substring(count,s.indexOf(count+1,' ')));
start(s.indexOf(count+1,' '));
}
if (count==last)
{
tempS+=reverse(s.substring(count));
System.out.println( tempS);
}
}
public static String reverse(String s1)
{
s1.trim();
int l=s1.length();
String temp=null;
for(int i=l;i>0;i++)
{
temp+=s1.charAt(i);
}
temp+=" ";
return temp;
}
public static void main()throws Exception
{
start(0);
}
}
Comment