forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asjordi.java
30 lines (23 loc) · 898 Bytes
/
asjordi.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
public class TextParser {
public void parse(String text){
text = text.replace("\n", " ");
String[] textArray = text.split(" ");
int numOfWords = 0;
double meanWordsLength = 0;
int numOfSentences = 0;
String longestWord = "";
for (String word : textArray) {
if (word.length() != 0) {
numOfWords++;
meanWordsLength += word.length();
if (word.contains(".")) numOfSentences++;
if (longestWord.length() < word.length()) longestWord = word;
}
}
meanWordsLength /= numOfWords;
System.out.println("Number of words: " + numOfWords);
System.out.println("Mean: " + meanWordsLength);
System.out.println("Number of sentences: " + numOfSentences);
System.out.println("Longest word: " + longestWord);
}
}