Add 2 2 (String Tokenizer)
This commit is contained in:
parent
5277ba3836
commit
3cb31bb0a1
@ -9,13 +9,11 @@
|
|||||||
- Abgabe der Ergebnisse des Selbststudiums am 26.04.2024
|
- Abgabe der Ergebnisse des Selbststudiums am 26.04.2024
|
||||||
<br>Sowohl SourceCode, PDF als auch Word Datei
|
<br>Sowohl SourceCode, PDF als auch Word Datei
|
||||||
- VL 2 Aufgabe 1 (Erstellen von Testdaten)
|
- VL 2 Aufgabe 1 (Erstellen von Testdaten)
|
||||||
|
- VL 2 Aufgabe 2 (StringTokenizer)
|
||||||
|
|
||||||
|
|
||||||
- keine
|
- keine
|
||||||
|
|
||||||
## Angefangene unfertige Lösungen:
|
## Angefangene unfertige Lösungen:
|
||||||
|
|
||||||
- VL 2 aufg 2
|
|
||||||
|
|
||||||
|
|
||||||
- keine
|
- keine
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,22 +1,49 @@
|
|||||||
package part2.aufg2;
|
package part2.aufg2;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
public class Anwendung {
|
public class Anwendung {
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
try{
|
int numbers = 0;
|
||||||
|
int words = 0;
|
||||||
|
int tokens = 0;
|
||||||
|
|
||||||
|
String fileContent = "";
|
||||||
|
|
||||||
|
try{
|
||||||
String line;
|
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");
|
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);
|
LineNumberReader dataIN = new LineNumberReader(fileIN);
|
||||||
|
|
||||||
while ((line = dataIN.readLine()) != null) {
|
while ((line = dataIN.readLine()) != null) {
|
||||||
System.out.println(line);
|
fileContent += line + " ";
|
||||||
}
|
}
|
||||||
System.out.println("end of file");
|
|
||||||
|
dataIN.close();
|
||||||
}
|
}
|
||||||
catch (Throwable e){
|
catch (Throwable e){
|
||||||
System.out.println("smth went wrong!");
|
System.out.println("smth went wrong!");
|
||||||
System.out.println(e);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
Wenn Robert mich lesen kann ist Matti cool!
|
Dieser Text hat 6 Worte und 2 Zahlen
|
||||||
Sehr cool sogar.
|
Das war eine Lüge es sind 8 und 2 mehr
|
Loading…
Reference in New Issue
Block a user