forked from joharbatta/DataStructure-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevSpecial.java
More file actions
30 lines (29 loc) · 784 Bytes
/
Copy pathrevSpecial.java
File metadata and controls
30 lines (29 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.*;
public class revSpecial {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
String str = s.nextLine();
reverseTheString(str);
}
static void reverseTheString(String s) {
char str[]=s.toCharArray();
int r = str.length - 1, l = 0;
while (l < r)
{
if (!Character.isAlphabetic(str[l]))
l++;
else if(!Character.isAlphabetic(str[r]))
r--;
else
{
char tmp = str[l];
str[l] = str[r];
str[r] = tmp;
l++;
r--;
}
}
String rev= new String(str);
System.out.println(rev);
}
}