String Reverse

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import java.util.

*;
public class main{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
String s1=s.nextLine();
char[] ch=s1.toCharArray();
char[] ch1=new char[s1.length()];
ArrayList<Character> al=new ArrayList<>();
for(int i=0;i<ch.length;i++)
{
char c=ch[i];
if((c>=65 && c<=90) || (c>=97 && c<=122) || (c>=48 && c<=57))
{
al.add(c);
ch1[i]='0';
}
else
{
ch1[i]=c;
}
}
Collections.reverse(al);
int t=0;
for(int i=0;i<ch.length;i++)
{
if(ch1[i]=='0')
{
System.out.print(al.get(t++));
}
else
{
System.out.print(ch1[i]);
}
}
}
}

You might also like