-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpattern.java
More file actions
40 lines (39 loc) · 1.14 KB
/
pattern.java
File metadata and controls
40 lines (39 loc) · 1.14 KB
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
39
40
import java.util.*;
import java.lang.*;
import java.io.*;
public class pattern {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// for(int i=1;i<=30;i++){
System.out.println(countSay("21", 1));
// }
}
public static String countSay(String s,int n){
if(n==0){
return s;
}
else{
String ans = "";
for(int i=0;i<s.length();){
for(int j=i;j<s.length();j++){
if(s.charAt(j)==s.charAt(i) && j!=s.length()-1){
continue;
}
else{
if(j==s.length()-1){
ans += (j-i+1)+""+(s.charAt(i));
i= j+1;
}
else{
ans += (j-i)+""+(s.charAt(i));
i = j;
}
break;
}
}
}
System.out.println("this is ans "+ans);
return countSay(ans,n-1);
}
}
}