Given a string is :
input: str="a,b$c"
output: str="c,b$a"
input: str="$b,c,d!e$"
output: str="$e,d,c!b$"
class
StringReverseWithoutAffectingSymbol
{
public static void stringReverse(String
input)
{
char ch[]=input.toCharArray();
String
revStr="";
System.out.println("Given string
is::"+input);
for(int i=input.length()-1;i>=0;i--)
{ if(Character.isLetter(ch[i]))
revStr+=ch[i];
}
char temp[]=revStr.toCharArray();
int k=0;
for(int j=0;j<ch.length;j++)
{
if(Character.isLetter(ch[j]))
{
ch[j]=temp[k++];
}
}
System.out.println("Reversed
string is::"+new String(ch));
System.out.println("--------------------------------------");
}
public static void main(String[] args)
{
stringReverse("a,b$c");
stringReverse("a!@bc&d");
}
}
Output: