forked from karzhouAndrew/JavaRepository
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDopLab7.java
More file actions
62 lines (54 loc) · 1.77 KB
/
Copy pathDopLab7.java
File metadata and controls
62 lines (54 loc) · 1.77 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package dopLab7;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DopLab7 {
public int numberVowels(String str) {
Pattern pattern = Pattern.compile("[аоиеёэыуюяАОИЕЁЭЫУЮЯ]");
Matcher matcher = pattern.matcher(str);
int count = 0;
while (matcher.find()) {
count++;
}
return count;
}
public int numberConsonants(String str) {
Pattern pattern = Pattern.compile("[бвгджзйклмнпрстфхцчшщБВГДЖЗЙКЛМНПРСТФХЦЧШЩ]");
Matcher matcher = pattern.matcher(str);
int count = 0;
while (matcher.find()) {
count++;
}
return count;
}
public void numberSentences(String str) {
Pattern pattern = Pattern.compile("([А-ЯA-Z](|[^?!.\\(]|\\([^\\)]*\\))*[.?!])");
Matcher matcher = pattern.matcher(str);
int count = 1;
while (matcher.find()) {
String sentence = matcher.group();
System.out.println("Предложение" + count + ". Длина: " + sentence.length() + " - " + sentence);
count++;
}
}
public int numberSpaces(String str) {
Pattern pattern = Pattern.compile("\\s");
Matcher matcher = pattern.matcher(str);
int count = 0;
while (matcher.find()) {
count++;
}
return count;
}
public int numberParagraphs(String str) {
Pattern pattern = Pattern.compile("\\n");
Matcher matcher = pattern.matcher(str);
int count = 0;
while (matcher.find()) {
count++;
}
return count;
}
public String withoutSpaces(String str) {
return str.replaceAll("\\s+", "");
}
}