-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileReader.java
52 lines (47 loc) · 1.18 KB
/
FileReader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.io.File;
import java.util.Scanner;
/*
* Created by Noah Shaw
*/
public class FileReader {
public static void main(String[] args) {
// TODO Auto-generated method stub
readFile("file.txt");
}
public static void readFile(String aFileName)
{
try
{
Scanner fileScanner = new Scanner(new File(aFileName));
int count = 0;
String file = "";
while(fileScanner.hasNextLine())
{
file = file + fileScanner.next();
}
fileScanner.close();
String newString = "";
for(int i = 0; i < file.length(); i++)
{
char c = file.charAt(i);
c = Character.toLowerCase(c);
if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
{
newString = newString + c;
}
}
for(int i = 0; i < newString.length(); i++)
{
if(newString.charAt(i) == 'a' && newString.charAt(i+1) == 'e' && newString.charAt(i+2) == 'i' && newString.charAt(i+3) == 'o' && newString.charAt(i+4) == 'u')
{
count++;
}
}
System.out.println("The file " + "\"" + aFileName + "\"" + " has \"AEIOU\" in order " + count + " times.");
}
catch(Exception e)
{
System.out.println(e);
}
}
}