Skip to content

Commit 0f5644f

Browse files
Add files via upload
1 parent 7757232 commit 0f5644f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Diff for: reverseonlycharacter.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class reverseonlycharacter{
2+
public static void main(String[] args){
3+
String str="12ab$c";
4+
//output string="12cb$a"
5+
char[] c=str.toCharArray();
6+
int left=0;
7+
int right=c.length-1;
8+
while(left<right){
9+
if(!Character.isAlphabetic(c[left])){
10+
left++;
11+
}else if(!Character.isAlphabetic(c[right])){
12+
right--;
13+
}else{
14+
char temp=c[left];
15+
c[left]=c[right];
16+
c[right]=temp;
17+
left++;
18+
right--;
19+
20+
}
21+
}
22+
String res=new String(c);
23+
System.out.println(res);
24+
25+
}
26+
}

0 commit comments

Comments
 (0)