28 lines
837 B
Java
28 lines
837 B
Java
package Semester2;
|
|
|
|
import java.util.StringTokenizer;
|
|
|
|
public class Vorlesung1part2 {
|
|
|
|
public static void main(String[] args) {
|
|
String input = "Dieser Text hat 6 Worte und 2 Zahlen.";
|
|
StringTokenizer tokenizer = new StringTokenizer(input);
|
|
int zahlcount = 0;
|
|
int wortcount = 0;
|
|
|
|
while (tokenizer.hasMoreTokens()) {
|
|
String wort = tokenizer.nextToken();
|
|
if (wort.matches("\\d+")) {
|
|
System.out.println("ZAHL: " + wort);
|
|
zahlcount++;
|
|
} else {
|
|
System.out.println("WORT: " + wort);
|
|
wortcount++;
|
|
}
|
|
}
|
|
System.out.println("Zahlen: " + zahlcount);
|
|
System.out.println("Wörter: " + wortcount);
|
|
System.out.println("Insgesamt: " + (wortcount+zahlcount));
|
|
}
|
|
}
|