-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseString.java
More file actions
26 lines (25 loc) · 877 Bytes
/
Copy pathReverseString.java
File metadata and controls
26 lines (25 loc) · 877 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
package StringBasedProblems;
//output
//tce jo++rpwen
public class ReverseString {
public static void main(String[] args) {
String s = "new pr++oject?";
char ch[] = s.toCharArray();
int i = 0, j = ch.length - 1;
while (i < j) {
while (!((ch[i] >= 'a' && ch[i] <= 'z') || (ch[i] >= 'A' && ch[i] <= 'Z')))
i++;
while (!((ch[j] >= 'a' && ch[j] <= 'z') || (ch[j] >= 'A' && ch[j] <= 'Z')))
j--;
if (((ch[i] >= 'a' && ch[i] <= 'z') || (ch[i] >= 'A' && ch[i] <= 'Z'))
&& ((ch[j] >= 'a' && ch[j] <= 'z') || (ch[j] >= 'A' && ch[j] <= 'Z'))) {
char temp = ch[i];
ch[i] = ch[j];
ch[j] = temp;
i++;
j--;
}
}
System.out.println(String.valueOf(ch));
}
}