-
I'm new to java.. Please help ^^
I got this program from a friend and I would like to know if it could be modified or it could be change in any other way. I just study java for 3 months so I don't really know many methods like others. Thank you =)
import java.util.Scanner;
import java.io.*;
public class CountVowel2 {
public static void main(String[]args) {
File txtFile;
FileReader in;
BufferedReader readFile;
String fileName;
String txt, letter;
int vowelsum = 0;
Scanner input = new Scanner(System.in);
System.out.print("Enter the file name: ");
fileName = input.nextLine();
try {
txtFile = new File(fileName);
in = new FileReader(txtFile);
readFile = new BufferedReader(in);
while ((txt = readFile.readLine()) != null) {
txt = txt.toLowerCase();
for (int i = 1; i <= txt.length(); i++) {
letter = txt.substring(i-1, i);
if (letter.matches("[aeiou]")) {
vowelsum +=1;
}
}
}
System.out.println("The number of vowels in " + fileName + " is " + vowelsum + ".");
readFile.close();
in.close();
} catch (FileNotFoundException e) {
System.out.println("File does not exist or could not be found.");
System.err.println("FileNotFoundException: " + e.getMessage());
} catch (IOException e) {
System.out.println("Problem reading file.");
System.err.println("IOException: " + e.getMessage());
}
}
}
-
In what manner do you want to modify or change it?
Similar Threads
-
Replies: 9
Last Post: 09-19-2007, 05:58 AM
-
Replies: 1
Last Post: 05-13-2005, 06:46 AM
-
By Rob Abbe in forum Talk to the Editors
Replies: 44
Last Post: 01-13-2003, 02:57 PM
-
By JJ in forum Enterprise
Replies: 1
Last Post: 07-06-2000, 04:50 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks