47 lines
1.3 KiB
Java
47 lines
1.3 KiB
Java
import java.io.BufferedReader;
|
|
import java.io.FileReader;
|
|
import java.io.IOException;
|
|
|
|
public class P15 {
|
|
public static void main(String[] args) {
|
|
String filename = "P15.in";
|
|
|
|
int letterCount = 0;
|
|
int vowelCount = 0;
|
|
int wordCount = 0;
|
|
|
|
try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
|
|
int cint;
|
|
boolean eating = true;
|
|
|
|
while ((cint = br.read()) != -1) {
|
|
char c = (char) cint;
|
|
|
|
if (Character.isLetter(c)) {
|
|
eating = false;
|
|
letterCount++;
|
|
|
|
if (isVowel(Character.toLowerCase(c))) {
|
|
vowelCount++;
|
|
}
|
|
} else {
|
|
if (!eating) {
|
|
eating = true;
|
|
wordCount++;
|
|
}
|
|
}
|
|
}
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
System.out.println("Letter count: " + letterCount);
|
|
System.out.println("Vowel count: " + vowelCount);
|
|
System.out.println("Word count: " + wordCount);
|
|
}
|
|
|
|
private static boolean isVowel(char c) {
|
|
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
|
|
}
|
|
}
|