-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstringabb.java
More file actions
46 lines (41 loc) · 906 Bytes
/
stringabb.java
File metadata and controls
46 lines (41 loc) · 906 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
39
40
41
42
43
44
45
46
package selfpractice;
import java.util.Scanner;
public class stringabb {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
String str = s.next();
boolean res = correctstr(str);
System.out.println(res);
}
public static boolean correctstr(String str) {
boolean ans = false;
if (str.length() == 0) {
ans = true;
}
char ch = str.charAt(0);
String ros = str.substring(1);
if (ch == 'a') {
if(str.length()==1)
{
ans = true;
}
else if (str.charAt(1)== 'a') {
ans = true;
correctstr(ros);
}
else if (str.length()>=3 && str.charAt(1) == 'b' && str.charAt(2) == 'b') {
ros = str.substring(3);
ans = true;
correctstr(ros);
}
else {
ans = false;
}
}
else{
ans=false;
}
return ans;
}
}