Hey guys,
As the title says, I want to know how I can reverse the characters in a string, but retaining the placement of the words as such, here's the code I used:
class reverse
{
void reverse(String s)
{
int l=s.length(),j=0;
String s1="";
for(;j<l;j++)
{
char a=s.charAt(j);
if(a==' ')
{
int p=j-1;
for(int i=p;i>;i++)
{
char b=s.charAt();
s1+=b;
}
}
}
System.out.println(s1);
}
}
But in line 12, I have no clue as to what integer value to give in the for loop...can anyone help me out?