Skip to content

Commit

Permalink
Reto #19 - Java
Browse files Browse the repository at this point in the history
  • Loading branch information
ASJordi committed Jul 24, 2023
1 parent 9a76f10 commit a2058a6
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Retos/Reto #19 - ANÁLISIS DE TEXTO [Media]/java/asjordi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);

}

}

0 comments on commit a2058a6

Please sign in to comment.