46
P15.java
Normal file
46
P15.java
Normal file
@@ -0,0 +1,46 @@
|
||||
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';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user