Modify the readFromDisk method to only output vowels for each line read from a f
ID: 3535808 • Letter: M
Question
Modify the readFromDisk method to only output vowels for each line read from a file.
Example, if a disk has the following text:
hello world!
this is great
testing
The program would print to console only vowels:
eoo
iiea
ei
public static void readFromDisk(String filename) {
System.out.println("Reading from file (" + filename + ") >");
try {
BufferedReader br = new BufferedReader(new FileReader("C:\Users\gmuclass\Downloads\" + filename));
String s;
while((s = br.readLine()) != null) {
System.out.println(s);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Explanation / Answer
public static void readFromDisk(String filename) {
System.out.println("Reading from file (" + filename + ") >");
try {
BufferedReader br = new BufferedReader(new FileReader("C:\Users\gmuclass\Downloads\" + filename));
String s;
while((s = br.readLine()) != null) {
if(s=='a' || s == 'e' || s== 'i' || s== "o' || s== 'u')
System.out.println(s);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.