Add 2 2 (String Tokenizer)

This commit is contained in:
Matti 2024-05-02 22:08:44 +02:00
parent 5277ba3836
commit 3cb31bb0a1
5 changed files with 2031 additions and 92 deletions

View File

@ -9,13 +9,11 @@
- Abgabe der Ergebnisse des Selbststudiums am 26.04.2024
<br>Sowohl SourceCode, PDF als auch Word Datei
- VL 2 Aufgabe 1 (Erstellen von Testdaten)
- VL 2 Aufgabe 2 (StringTokenizer)
- keine
## Angefangene unfertige Lösungen:
- VL 2 aufg 2
- keine

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +1,49 @@
package part2.aufg2;
import java.io.*;
import java.util.StringTokenizer;
public class Anwendung {
public static void main(String[] args){
try{
int numbers = 0;
int words = 0;
int tokens = 0;
String fileContent = "";
try{
String line;
FileReader fileIN = new FileReader("C:\\Users\\dh10mbo\\OneDrive - Durr Group\\Documents\\Uni\\S2\\Repos\\S2_Aufgaben\\src\\part2\\aufg2\\files\\input\\input.txt");
LineNumberReader dataIN = new LineNumberReader(fileIN);
while ((line = dataIN.readLine()) != null) {
System.out.println(line);
fileContent += line + " ";
}
System.out.println("end of file");
dataIN.close();
}
catch (Throwable e){
System.out.println("smth went wrong!");
System.out.println(e);
}
StringTokenizer st = new StringTokenizer(fileContent);
String token;
while (st.hasMoreTokens()){
token = st.nextToken();
if (token.matches("\\d+")){
numbers++;
tokens++;
System.out.println("Number: " + token);
}else if (token.matches("[a-zäöüA-ZÄÖÜ]+")){
words++;
tokens++;
System.out.println("Word: " + token);
}
}
System.out.println("\n========================\n");
System.out.println("Total Tokens : " + tokens);
System.out.println("Numbers : " + numbers);
System.out.println("Words : " + words);
}
}

View File

@ -1,2 +1,2 @@
Wenn Robert mich lesen kann ist Matti cool!
Sehr cool sogar.
Dieser Text hat 6 Worte und 2 Zahlen
Das war eine Lüge es sind 8 und 2 mehr