forked from 1ramagrawal0610/h4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathar04.java
More file actions
38 lines (35 loc) · 908 Bytes
/
ar04.java
File metadata and controls
38 lines (35 loc) · 908 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
36
37
38
package ex;
public class RSL8 {
public static void main(String[] args) {
String str= "i.like.this.program.very.much";
System.out.println(revString1(str));
}
public static String revString(String str) {
String[] words= str.split("[.]", 0);
String revString= "";
int n=words.length;
for(int i=n-1; i>=0;i--){
revString+=words[i];
if(i!=0)revString+='.';
}
return revString;
}
public static String revString1(String str) {
String revString= "";
int n=str.length();
String word="";
boolean eo=false;
for(int i=0; i<n;i++){
if(str.charAt(i)!='.') {
word=eo?(str.charAt(i)+word):word+str.charAt(i);
}
else {
revString+=word+'.';
word="";
eo=!eo;
}
}
revString+=word;
return revString;
}
}