-
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.
- Loading branch information
1 parent
02a905c
commit ccd8db8
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
Retos/Reto #19 - ANÁLISIS DE TEXTO [Media]/java/EspinoLeandroo.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,37 @@ | ||
public class EspinoLeandroo { | ||
|
||
public static void main(String[] args) { | ||
String texto = "Este es un ejemplo de análisis de texto. Contiene varias oraciones y palabras de diferentes longitudes."; | ||
|
||
int numeroPalabras = 0; | ||
int longitudTotalPalabras = 0; | ||
int numeroOraciones = 0; | ||
String palabraMasLarga = ""; | ||
|
||
String[] palabras = texto.split("\\s+"); | ||
|
||
for (String palabra : palabras) { | ||
// Elimina signos de puntuación al final de las palabras | ||
|
||
if (palabra.contains(".") || palabra.contains("!") || palabra.contains("?")) { | ||
numeroOraciones++; | ||
} | ||
|
||
palabra = palabra.replaceAll("[.,;!?]+$", ""); | ||
|
||
numeroPalabras++; | ||
longitudTotalPalabras += palabra.length(); | ||
|
||
if (palabra.length() > palabraMasLarga.length()) { | ||
palabraMasLarga = palabra; | ||
} | ||
} | ||
|
||
double longitudMediaPalabras = (double) longitudTotalPalabras / numeroPalabras; | ||
|
||
System.out.println("Número total de palabras: " + numeroPalabras); | ||
System.out.println("Longitud media de las palabras: " + longitudMediaPalabras); | ||
System.out.println("Número de oraciones: " + numeroOraciones); | ||
System.out.println("Palabra más larga: " + palabraMasLarga); | ||
} | ||
} |