-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem1_String_change.java
More file actions
35 lines (30 loc) · 894 Bytes
/
Problem1_String_change.java
File metadata and controls
35 lines (30 loc) · 894 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
31
32
33
34
35
public class Problem1_String_change {
public Problem1_String_change(){
}
public static void Do(char[] Str){
int slowIndex = 0;
int fastIndex = 0;
while (fastIndex < Str.length) {
if (Str[fastIndex] == ' ') {
fastIndex++;
} else {
if (slowIndex != fastIndex) {
char temp = Str[slowIndex];
Str[slowIndex] = Str[fastIndex];
Str[fastIndex] = temp;
slowIndex++;
fastIndex++;
continue;
}
fastIndex++;
slowIndex = fastIndex;
}
}
}
public static void main(String[] Args){
char [] A ={'a','b','c',' ',' ','d','e','f',' ',' ',' ',' ','g','h',' ','i'};
Do(A);
String s = new String(A);
System.out.println(s);
}
}