-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexical.java
49 lines (42 loc) · 1.16 KB
/
lexical.java
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
47
48
49
public class Tpp{
public static void main(String[] args) {
System.out.println("Entrez une chaîne : ");
Scanner scanner = new Scanner(System.in);
String tc = scanner.nextLine();
if (isValid(tc)) {
System.out.println("La chaîne est valide.");
} else {
System.out.println("La chaîne est invalide.");
}
}
private static boolean isValid(String input) {
char[] chars = input.toCharArray();
int length = chars.length;
int tc = 0;
if (tc < length && chars[tc] == 'a') {
tc++;
while (tc < length && chars[tc] == 'a') {
tc++;
}
} else {
return false;
}
if (tc < length && chars[tc] == 'd') {
tc++;
} else {
return false;
}
while (tc < length && chars[tc] == 'b') {
tc++;
}
if (tc < length && chars[tc] == 'c') {
tc++;
while (tc < length && chars[tc] == 'c') {
tc++;
}
} else {
return false;
}
return tc == length;
}
}