-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4261 from ASJordi/main
Reto #19 - Java
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
Retos/Reto #19 - ANÁLISIS DE TEXTO [Media]/java/asjordi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
|
||
} |